[Ruby] Mail
类使用代码示例
在使用下面的例子之前,请安装并引入 Mail
, 在安装 Mail 之前,请确认已安装 OpenSSL library
gem install mail
require 'mail'
Mail.defaults do
delivery_method :smtp, { :address => "cloud.submail.cn",
:port => 587,
:domain => "yourdomain.com",
:user_name => "your_app_id",
:password => "your_app_key",
:authentication => 'plain',
:enable_starttls_auto => true }
end
mail = Mail.deliver do
to 'leo@submail.cn'
from 'SUBMAIL '
subject 'testing subject'
text_part do
body 'testing text body'
end
html_part do
content_type 'text/html; charset=UTF-8'
body 'testing html body'
end
Mail.defaults do
delivery_method :smtp, { :address => "cloud.submail.cn",
:port => 587,
:domain => "yourdomain.com",
:user_name => "your_app_id",
:password => "your_app_key",
:authentication => 'plain',
:enable_starttls_auto => true }
end
mail = Mail.deliver do
to 'leo@submail.cn'
from 'SUBMAIL '
subject 'testing subject'
text_part do
body 'testing text body'
end
html_part do
content_type 'text/html; charset=UTF-8'
body 'testing html body'
end
关于 SMTP 配置,请参阅开发者文档 SMTP