The following example shows how to send an email through SMTP using Ruby.
# install `mail` gem first: `gem install mail`
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 25,
:address => "smtpdm.aliyun.com",
:user_name => "domaintest@dm.aliyun.com",
:password => "****",
:enable_starttls_auto => false,
:openssl_verify_mode => 'none',
}
end
mail = Mail.deliver do
to 'test@test.com'
from 'domaintest@dm.aliyun.com'
subject 'Hello'
text_part do
body 'Testing mail'
end
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.