Forum: Ruby on Rails Problem with Rails Action Mailer

Posted by Rajesh B. (rajesh_b)
on 2011-11-16 11:52
Hi all,

I have a problem with my action mailer .!

When i send mail in the email it shows the html tags same written as in
mailer view html


here is my code:

In the Model :----------------

class CronjobMailer < ActionMailer::Base
 def cronjob(sender,recipients, subject, message, late_commers)
   @bcc = recipients
   @recipients = 'support@eabyas.in'
   @from = sender
   @subject = subject
   @late_commers = late_commers
   @sent_on = Time.now
   @body[:message] = message
 end
end

:----------------


In the Cronjob_mailer view in cronjob.html.erb

<!DOCTYPE html>
<html>
 <head>
   <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
 </head>
 <body>
   <h1>Welcome to example.com</h1>
   <p>
     You have successfully signed up to example.com,
     your username is: .<br/>
   </p>
   <p>
     To login to the site, just follow this link: .
   </p>
   <p>Thanks for joining and have a great day!</p>
 </body>
</html>


and here is how i am initiating the mailer


CronjobMailer::deliver_cronjob(sender,recipient_list,@subject,@messege,
@late_commers)


when i deliver mail in the email it gives me the same code instead of
html output .

Please help me
Thanks in advance
Posted by comopasta Gr (comopasta)
on 2011-11-16 13:04
Rajesh B. wrote in post #1032117:
> Hi all,
>
> I have a problem with my action mailer .!
>
> When i send mail in the email it shows the html tags same written as in
> mailer view html

>
> and here is how i am initiating the mailer
>
>
> CronjobMailer::deliver_cronjob(sender,recipient_list,@subject,@messege,
> @late_commers)
>
>
> when i deliver mail in the email it gives me the same code instead of
> html output .
>

Interesting. What version of Rails are you using? I'm still in 3.0 and I 
deliver stuff like in the rails guide:

UserMailer.welcome_email(@user).deliver

In your case I would see it like 
CronjobMailer.cronjob(sender,recipient_list,@subject,@messege, 
@late_commers).deliver have you tried something like that?
Posted by Rajesh B. (rajesh_b)
on 2011-11-16 13:55
I am using rails 2.3.8
Do i require any other gem ?
Posted by comopasta Gr (comopasta)
on 2011-11-16 14:13
Rajesh B. wrote in post #1032142:
> I am using rails 2.3.8
> Do i require any other gem ?

Well it is long time ago since I used Rails 2.3
For sure the Rails guide that I suggested is for Rails 3.0.x and the 
mailer logic was changed and improved from 2.3 to 3.0. Many things 
changed there.

If you are just starting the project I would recommend upgrading at 
least to Rails 3.0 and if you dare even to Rails 3.1 which is the new 
beast. If you need to stick to rails 2.3 maybe this is old enough 
http://railscasts.com/episodes/61-sending-email

Cheers.
Posted by Rajesh B. (rajesh_b)
on 2011-11-16 14:18
I have added  @content_type = 'text/html' in the mailer method it
worked.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.