SMTP-Ruby

Last Updated: Aug 09, 2017

Send a mail via SMTP using Ruby

  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. text_part do
  18. body 'Testing mail'
  19. end
  20. end

Note: Replace the content after “:user_name =>” with the sender address, the content after “:password =>” with your DirectMail password, the content after “to ‘“ with the recipient address, and the content after “from ‘“ with the sender address.

Thank you! We've received your feedback.