Hi, I was just wondering how i would write a ruby script to send an
email using the gmail smtp. Here is what I have so far:
require ‘rubygems’
require ‘action_mailer’
class SimpleMailer < ActionMailer::Base
def simple_message(recipient)
from ‘[email protected]’
recipients recipient
subject ‘yay I just sent this’
body ‘hope this works’
end
end
ActionMailer::Base.smtp_settings = { :address =>
‘smtp.gmail.com’, :port => ‘25’, :user_name =>
‘[email protected]’, :password => ‘my_password’, :authentication =>
‘login’ }
SimpleMailer.deliver_simple_message(‘[email protected]’)
Unfortunately, when run I get these error messages:
ruby mail.rb
/usr/local/lib/ruby/1.8/net/smtp.rb:680:in check_response': 530 5.7.0 Must issue a STARTTLS command first. z80sm1963933pyg.31 (Net::SMTPUnknownError) from /usr/local/lib/ruby/1.8/net/smtp.rb:582:in
auth_login’
from /usr/local/lib/ruby/1.8/net/smtp.rb:686:in critical' from /usr/local/lib/ruby/1.8/net/smtp.rb:581:in
auth_login’
from /usr/local/lib/ruby/1.8/net/smtp.rb:571:in __send__' from /usr/local/lib/ruby/1.8/net/smtp.rb:571:in
authenticate’
from /usr/local/lib/ruby/1.8/net/smtp.rb:411:in do_start' from /usr/local/lib/ruby/1.8/net/smtp.rb:378:in
start’
from /usr/local/lib/ruby/1.8/net/smtp.rb:316:in start' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/ action_mailer/base.rb:627:in
perform_delivery_smtp’
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/
action_mailer/base.rb:508:in __send__' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/ action_mailer/base.rb:508:in
deliver!’
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/
action_mailer/base.rb:383:in `method_missing’
from mail.rb:15
Seems like the actionmailer has a bug. I tested the actionmailer and the
email does not get sent.
Â
thanks,
Deepak
— On Fri, 6/20/08, APNelson.L [email protected] wrote:
From: APNelson.L [email protected]
Subject: Using actionmailer to send an email
To: “ruby-talk ML” [email protected]
Date: Friday, June 20, 2008, 6:13 PM
Hi, I was just wondering how i would write a ruby script to send an
email using the gmail smtp. Here is what I have so far:
require ‘rubygems’
require ‘action_mailer’
class SimpleMailer < ActionMailer::Base
def simple_message(recipient)
from ‘[email protected]’
recipients recipient
subject ‘yay I just sent this’
body ‘hope this works’
end
end
ActionMailer::Base.smtp_settings = { :address =>
‘smtp.gmail.com’, :port => ‘25’, :user_name =>
‘[email protected]’, :password => ‘my_password’,
:authentication =>
‘login’ }
SimpleMailer.deliver_simple_message(‘[email protected]’)
Unfortunately, when run I get these error messages:
ruby mail.rb
/usr/local/lib/ruby/1.8/net/smtp.rb:680:in check_response': 530 5.7.0 Must issue a STARTTLS command first. z80sm1963933pyg.31 (Net::SMTPUnknownError) from /usr/local/lib/ruby/1.8/net/smtp.rb:582:in
auth_login’
from /usr/local/lib/ruby/1.8/net/smtp.rb:686:in critical' from /usr/local/lib/ruby/1.8/net/smtp.rb:581:in
auth_login’
from /usr/local/lib/ruby/1.8/net/smtp.rb:571:in __send__' from /usr/local/lib/ruby/1.8/net/smtp.rb:571:in
authenticate’
from /usr/local/lib/ruby/1.8/net/smtp.rb:411:in do_start' from /usr/local/lib/ruby/1.8/net/smtp.rb:378:in
start’
from /usr/local/lib/ruby/1.8/net/smtp.rb:316:in start' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/ action_mailer/base.rb:627:in
perform_delivery_smtp’
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/
action_mailer/base.rb:508:in __send__' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/ action_mailer/base.rb:508:in
deliver!’
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.1.0/lib/
action_mailer/base.rb:383:in `method_missing’
from mail.rb:15
so how would I go about writing a scrip to send an email then?
From: APNelson.L [mailto:[email protected]]
ruby mail.rb
/usr/local/lib/ruby/1.8/net/smtp.rb:680:in `check_response’: 530 5.7.0
Must issue a STARTTLS command first. z80sm1963933pyg.31
this means that the server requires tls.
check the rails list, they know better about actionmailer and its
plugins.
kind regards -botp
On Jun 21, 8:45 am, Phlip [email protected] wrote:
On Jun 22, 5:47 am, Junkone [email protected] wrote:
I tried that once, and I could not find a POP3 server that was lite, like
a student’s sketch of one. They were all real servers, top-heavy and
configuration-hostile.
Then turn on TLS security, to emulate how GMail does it…
–
Phlip
http://assert2.rubyforge.org/assert_yin_yang.html- Hide quoted text -
you have to add this piece of code for gmail smtp to work thro action
mailer
INSTALL THE FOLLOWING AS smtp_tls UNDER C:\ruby\lib\ruby\gems\1.8\gems
\actionmailer-2.0.2\lib
############## START OF CODE ##################################
require “openssl”
require “net/smtp”
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, ‘SMTP session already started’ if @started
check_auth_args user, secret, authtype if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
check_response(critical { recv_response() })
do_helo(helodomain)
raise 'openssl library not installed' unless defined?(OpenSSL)
starttls
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
do_helo(helodomain)
authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not
@socket.closed?
@socket = nil
end
end
def do_helo(helodomain)
begin
if @esmtp
ehlo helodomain
else
helo helodomain
end
rescue Net::ProtocolError
if @esmtp
@esmtp = false
@error_occured = false
retry
end
raise
end
end
def starttls
getok(‘STARTTLS’)
end
def quit
begin
getok(‘QUIT’)
rescue EOFError
end
end
end
##########END OF CODE #############################################
On Jun 20, 2008, at 7:13 PM, APNelson.L wrote:
subject 'yay I just sent this'
you need to patch Net::SMTP to support tls, this is one of the easiest
ways:
http://drawohara.com/post/37908300/rails-using-ssl-tls-with-actionmailer-gmail
cheers.
a @ http://codeforpeople.com/
I really like this plugin for doing this
OpenRain.com is for sale | HugeDomains. Seems though like
this should be in ActiveMailer though… I am on Rails 2.1, and a lot
of the posts are referring to Rails 1.x!