Step 1
Please make sure that you have installed gem mail.
Step 2
Please change the following in this script:
- sender@example.com: the sender’s email address.
- recipient@example.com: the recipient’s email address.
- USERNAME: your SMTP2GO username.
- PASSWORD: your SMTP2GO password.
- yourdomain.com: your domain name.
#!/usr/bin/ruby
begin
require 'rubygems'
require 'mail'
rescue LoadError => e
puts "Missing Dependency #{e.message}"
exit 1
end
mail = Mail.new do
from 'sender@example.com'
to 'recipient@example.com'
subject "Your Subject"
text_part do
body 'It is a text message'
end
html_part do
content_type 'text/html; charset=UTF-8'
body 'It is a html message'
end
end
Net::SMTP.start('mail.smtp2go.com', 2525, 'yourdomain.com', 'USERNAME', 'PASSWORD', :login) do |smtp|
smtp.send_message(mail.to_s, 'sender@example.com', 'recipient@example.com')
#Port 8025, 587 and 25 can also be used.
end