Rails 4 mailers with gmail smtp

喜你入骨 提交于 2021-02-19 07:31:12

问题


I want to use the Mailer of Rails 4 with the Gmail's smtp configuration In my development file i set:

  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "gmail.com",
      :user_name            => "mymail@gmail.com",
      :password             => "mygmailpassword",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }

but i don't recive any mails. This is the output of the terminal:

To: antonioni.giovanni9@gmail.com
Message-ID: <55ffb56da9e91_aa929362303435c@pc-rails.mail>
Subject: Conferma ordine
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_55ffb56da807b_aa92936230342e1";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_55ffb56da807b_aa92936230342e1
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

so my application try to send an email but this not appear on my gmail dashboard. Any idea for resolve this trouble?


回答1:


Gmail smtp service need an APP PASSWORD for send a mail from a gmail account (for more info visit this link). After generating the password you must change the configuration of the development file:

  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "gmail.com",
      :user_name            => "mymail@gmail.com",
      :password             => "GENERATEDPASSWORD",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }

And then restart the server. For catching the error i've set: config.action_mailer.raise_delivery_errors = true (Thanks Dipak for the tip)




回答2:


You also need to change this: https://www.google.com/settings/security/lesssecureapps



来源:https://stackoverflow.com/questions/32690089/rails-4-mailers-with-gmail-smtp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!