Tuesday, January 3, 2012

SMTP check script in ruby.

Create ruby script to check SMTP with login credential.
You can test two authentication in this script i.e. plain and login.

vi     /opt/rubymailtest.rb


require 'net/smtp'

message = <
From: info@homework.do
To: sbtoalerts@gmail.com
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900

This is a test message.
END_OF_MESSAGE


#Net::SMTP.start('mail.exmaple.com') do |smtp|
#  smtp.send_message message, 'info@homework.do',
#                             'sbtoalerts@gmail.com'


# PLAIN
#Net::SMTP.start('mail.example.com', 25, 'mail.example.com',
#                'Your Account', 'Your Password', :plain)
 

# LOGIN
Net::SMTP.start('mail.example.com', 25, 'mail.example.com', 'username', 'passwd', :login) do |smtp|
      smtp.send_message message, 'info@homework.do',
                             'sbtoalerts@gmail.com'


#puts " done"
end