简体   繁体   English

带有Gmail SMTP的Rails 4邮件

[英]Rails 4 mailers with gmail smtp

I want to use the Mailer of Rails 4 with the Gmail's smtp configuration In my development file i set: 我想在Gmail的smtp配置中使用Mailer of Rails 4在我的开发文件中设置:

  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. 因此我的应用程序尝试发送电子邮件,但此电子邮件未显示在我的gmail仪表板上。 Any idea for resolve this trouble? 有解决这个麻烦的主意吗?

Gmail smtp service need an APP PASSWORD for send a mail from a gmail account (for more info visit this link ). Gmail smtp服务需要一个APP密码才能通过gmail帐户发送邮件(有关更多信息,请访问此链接 )。 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) 为了捕获我设置的错误: config.action_mailer.raise_delivery_errors = true (感谢Dipak的提示)

您还需要更改此设置: https : //www.google.com/settings/security/lesssecureapps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM