Friday, June 6, 2008

How to send a mail from application

After the configuration of action mailer. Perform the following task.

class Notifier < ActionMailer::Base
def send_email(user_details)
@recipients = "#{user[:email]}"
@from = "xyz@xyz.com"
@subject = "this is testing"
@sent_on = Time.now.utc
@content_type = "text/html"
@body = {}
url = "http://xyz.com/id=12312123"
@body.store('url', url)
@body.store('user', user)
render_message("signup", @body)
end
end


from controller call
def xyz
@user = User.new(params[:user])
if @user.save!
Notifier.send_email(@user)
end
end

and if you want a proper template should be forwarded then in ur view folder/notifier

create a file send_email.rhtml if you are using localization you can call as 'send_email_en.rhtml'
Dear, <%= @user[:login] %>
Welcome to xyz.com

thanks

1 comment:

Unknown said...

short and sweet.

Thanks Abhi, I could send mail.

Regards,
Prayas.