ruby gem mail的简单使用

目录

安装mail gem #

gem install mail

编写mail脚本 #

require 'mail'
smtp = { :address => 'smtp.163.com', :port => 25, :domain => '163.com',
:user_name => '[email protected]', :password => 'xxx',
:enable_starttls_auto => true, :openssl_verify_mode => 'none' }
Mail.defaults { delivery_method :smtp, smtp }
mail = Mail.new do
subject 'xxx'
add_file File.expand_path("/opt/xxx.log")
end
mail.deliver!

实现了发送带附件邮件的功能.