Tuesday, 25 July 2017

Send mail with mailgun


Follow this link=>
http://www.leemunroe.com/send-automated-email-ruby-rails-mailgun/

or

1. create your credentials=>
(config/development.rb)
config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :authentication => :plain,
    :address => "smtp.mailgun.org",
    :port => 587,
    :domain => "sandboxec6b35c5c7ad40ff9a7fc2959942ec87.mailgun.org",
    :user_name => "postmaster@sandboxec6b35c5c7ad40ff9a7fc2959942ec87.mailgun.org",
    :password => "764e70a2f8cb5ec1611e843fb1cd54c8"
  }



2. Generate your mailer by typing this in Terminal
rails g mailer model_mailer new_record_notification

3. Generate your mailer by typing this in Terminalrails g mailer model_mailer new_record_notification
4. app/mailers/model_mailer.rb and 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