SMTP 之 Ruby 调用示例

使用 Ruby 通过 SMTP 协议发信

  1. # install `mail` gem first: `gem install mail`
  2. require 'mail'
  3. Mail.defaults do
  4. delivery_method :smtp, {
  5. :port => 25,
  6. :address => "smtpdm.aliyun.com",
  7. :user_name => "domaintest@dm.aliyun.com",
  8. :password => "****",
  9. :enable_starttls_auto => false,
  10. :openssl_verify_mode => 'none',
  11. }
  12. end
  13. mail = Mail.deliver do
  14. to 'test@test.com'
  15. from 'domaintest@dm.aliyun.com'
  16. subject 'Hello'
  17. reply-to '设置回信地址'
  18. text_part do
  19. body 'Testing mail'
  20. end
  21. end

注:请在 :user_name => 后替换您的发信地址;:password => 后替换您的邮件推送密码;to ‘后替换收件人地址;from ‘后替换发信地址。