带有 gmail smtp 的 Rails 4 邮件程序 [英] Rails 4 mailers with gmail smtp

查看:71
本文介绍了带有 gmail smtp 的 Rails 4 邮件程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Gmail 的 smtp 配置中使用 Rails 4 的邮件程序在我的开发文件中,我设置了:

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

所以我的应用程序尝试发送电子邮件,但这没有出现在我的 gmail 仪表板上.有解决这个问题的想法吗?

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

推荐答案

Gmail smtp 服务需要一个应用密码才能从 Gmail 帐户发送邮件(有关更多信息,请访问此 链接).生成密码后必须更改开发文件的配置:

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
  }

然后重启服务器.为了捕捉我设置的错误:config.action_mailer.raise_delivery_errors = true(感谢 Dipak 的提示)

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

这篇关于带有 gmail smtp 的 Rails 4 邮件程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆