All Products
Search
Document Center

Direct Mail:SMTP - Ruby

Last Updated:Dec 15, 2017

The following example shows how to send an email through 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.
  • the content after “from ‘“ with the sender address.