Rails 设置 Action Mailer 使用 Gmail

Rails 设置

config.action_mailer.smtp_settings = {  address: 'smtp.gmail.com',  port: 587,  # optional  # domain: 'your-blog-address',  user_name: 'user-name@gmail.com',  password: 'password-here',  authentication: :plain,  enable_starttls_auto: true}

Gmail 设置

设置完毕之后,测试着发送一封邮件,结果是验证失败

ReplyMailer.new_reply_email('slogerdream@gmail.com', "fasdfasd", "fasdf").deliver!# Net::SMTPAuthenticationError: 534-5.7.14 

Google 了一下,发现是 Gmail 出于安全性考虑对非 Google 出品的 Mail 客户端默认无法通过,查了官方的文档,解决问题有两种方法。

第一种是进入 https://accounts.google.com/b/0/DisplayUnlockCaptcha,点击 继续 就行了

我用这种方法依旧不行,于是用了第二种方法:

进入 https://www.google.com/settings/security/lesssecureapps,选择 不够安全的应用的访问权限 为 启用,这样做会使账户变得不安全,但是由于我是创建的一个单独的帐号用来发送邮件,因此倒不在乎安全性。

最后再发送一次,检查邮箱,发现收到邮件啦~

Rails 设置 Action Mailer 使用 Gmail

相关文章:

你感兴趣的文章:

标签云: