我想测试我的ActionMailer类,但没有smtp服务器。我想用gmail发送这样的电子邮件。有人可以在谷歌和应用程序中的任何配置文件中提供所有必要配置的样本吗?
答案 0 :(得分:5)
GMail只提供SSL SMTP,因此您应该通过Net :: SMTP创建SSL SMTP连接。
查看这篇文章:
答案 1 :(得分:4)
我是用SSMTP做的。它充当SMTP服务器并代理真正的SMTP服务器。在Unix(在这种情况下是Ubuntu hardy)它使系统sendmail正常工作。
如果你也在Ubuntu上,请运行apt-get install ssmtp
来获取它。
这是一个基于我的示例配置文件。
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=aspmx.l.google.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
rewriteDomain=example.com
# The full hostname
hostname=yourhostname.example.com
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
# should turn on SSL & auth to google's SMTP server
# TODO change this user
UseTLS=YES
UseSTARTTLS=YES
AuthUser=yourgoogleuser@example.com.com
AuthPass=yourgooglepassword
您需要将其添加到environment.rb
或production/environment.rb
:
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.raise_delivery_errors = true