我用mail
Ruby 换Ruby https://github.com/mikel/mail
如何通过smtp服务器发送邮箱?如何指定地址和端口?Gmail应该使用什么设置?
github上的README
只给出了通过本地服务器发送的示例.
我用mail
Ruby 换Ruby https://github.com/mikel/mail
如何通过smtp服务器发送邮箱?如何指定地址和端口?Gmail应该使用什么设置?
github上的README
只给出了通过本地服务器发送的示例.
从http://lindsaar.net/2010/3/15/how_to_use_mail_and_actionmailer_3_with_gmail_smtp
要通过GMail发送,需要将Mail::SMTP
类配置为具有正确的值,因此要try 此操作,请打开IRB并键入以下内容:
require 'mail'
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => 'your.host.name',
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
最后一个块调用Mail.defaults
,这允许我们为从现在开始创建的所有邮件对象设置全局传递方法.超级用户提示,您不必使用全局方法,您可以直接在任何单个Mail::Message
对象上定义delivery_方法,并且每个邮箱都有不同的传递代理.如果您正在构建一个应用程序,其中有多个用户,且有不同的服务器处理他们的邮箱,这将非常有用.
Mail.deliver do
to 'mikel@test.lindsaar.net'
from 'ada@test.lindsaar.net'
subject 'testing sendmail'
body 'testing sendmail'
end