Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

mail sending program using ssl using gmail account

// sending mail using ruby through ssl

   1  
   2  require 'rubygems'
   3  require 'action_mailer'
   4  require "net/smtp"
   5  require "tlsmail"
   6  
   7  class MailSent < ActionMailer::Base
   8    def message(r = "", m = "", s = "", f = "", c = nil)
   9      begin
  10        fail StandardError, "No Recipient" if r.empty? #and b.empty?
  11        fail StandardError, "No Message" if m.empty? 
  12        fail StandardError, "No Subject" if s.empty?
  13        fail StandardError, "No From" if s.empty?
  14        from f
  15        recipients r
  16        cc c if c and !c.empty?
  17        subject s
  18        body m
  19      rescue Exception => e
  20        puts e
  21      end
  22    end
  23  end
  24  
  25  class SentMail
  26    def get_value(to,msg,sub,from,pass=nil,cc=nil)
  27      begin
  28  
  29        Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
  30        ActionMailer::Base.smtp_settings = {
  31          :address => "smtp.gmail.com",
  32          :port => "587",
  33          :domain => "gmail.com",
  34          :user_name => "example.com,
  35          :password => "youraccountpassword",
  36          :authentication => :plain
  37        }
  38        MailSent.deliver_message(to,msg,sub,from,cc)
  39      rescue Exception=>e
  40        puts e
  41      end
  42    end
  43  end
  44  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS