Send mail with mailgun
Follow this link=>
http://www.leemunroe.com/send-
or
1. create your credentials=>(config/
config.action_mailer.delivery_
config.action_mailer.smtp_
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "sandboxec6b35c5c7ad40ff9a7fc2
:user_name => "postmaster@
:password => "
}
2. Generate your mailer by typing this in Terminal
rails g mailer model_mailer new_record_notification3. Generate your mailer by typing this in Terminalrails g mailer model_mailer new_record_notification4. app/mailers/model_mailer.rband change the default from email:default from: "me@MYDOMAIN.com"
def new_record_notification(record )
@record = record
mail to: "recipient@MYDOMAIN.com", subject: "Success! You did it."
end
5. app/views/model_mailer/new_ record_notification.text.erb
Hi,
A new record has been added: <%= @record.name %>
Thanks
6. Send the email(in controller)
def create
@record = Record.new
if @record.save
ModelMailer.new_record_ notification(@record).deliver
redirect_to @record
end
end
No comments:
Post a Comment