/ ?>>

Send email from Ruby

By , February 8, 2011 5:05 pm

Here I will show you how to send email through ruby script.

Require NET/SMPT  library  in ruby script


require 'net/smtp'

Config SMTP authentication


def  send_email(to,opts={})

opts[:server]      ||= 'SERVER IP'

opts[:port]        ||= PORT_NUMBER

opts[:domain]      ||= "DOMAIN IP"

opts[:user_name]   ||="USERNAME"

opts[:password]    ||= "PASSWORD"

opts[:authentication]   ||="plain"

opts[:from]        ||= 'example@domain.com'

opts[:from_alias]  ||= 'FROM NAME'

opts[:subject]     ||= "SUBJECT SAMPLE"

opts[:body]        ||= "MESSAGE BODY"

 msg = <<END_OF_MESSAGE

From: #{opts[:from_alias]} <#{opts[:from]}>

To: <#{to}>

Subject: #{opts[:subject]}

Content-type: text/html

#{opts[:body]}

END_OF_MESSAGE
 Net::SMTP.start(opts[:server],opts[:port], opts[:domain],opts[:user_name], opts[:password],opts[:authentication]) do |smtp|

smtp.send_message msg, opts[:from], to

end

end

Now send email by passing arguments.


send_email "EMAIL ADDRESS", :body => "MESSAGE"

I hope this will helps you to send email through script.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

2 Responses to “Send email from Ruby”

  1. China visa…

    [...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]…

Leave a Reply

*

Panorama Theme by Themocracy