Reputation: 65
I'm using Action Mailer to send a daily email, but without Rails. I've also looked at other questions here: Action Mailer 3 without Rails, ActionMailer and Ramaze
Here's my code:
require 'action_mailer'
class Mailer < ActionMailer::Base
def daily_names_email(names,subject="test daily mail",to = "[email protected]")
@names = "test names"
mail(
:to => to,
:from => "[email protected]",
:subject => subject
) do |format|
format.text
format.html
end
end
end
Mailer.raise_delivery_errors = true
Mailer.delivery_method = :smtp
Mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 465,
:domain => "google",
:authentication => :plain,
:user_name => "[email protected]",
:password => "*****",
:enable_starttls_auto => true
}
Mailer.view_paths = File.dirname(__FILE__)
Mailer.logger = Logger.new(STDOUT)
email = Mailer.daily_names_email('hello')
puts email
email.deliver
Here's the Error output:
Date: Thu, 19 Jul 2012 08:46:18 +0800
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: test daily mail
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_500758da4a289_151082d87c104fb";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_500758da4a289_151082d87c104fb
Date: Thu, 19 Jul 2012 08:46:18 +0800
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <[email protected]>
/usr/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /usr/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
from /usr/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /usr/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /usr/lib/ruby/1.9.1/net/smtp.rb:929:in `recv_response'
from /usr/lib/ruby/1.9.1/net/smtp.rb:552:in `block in do_start'
from /usr/lib/ruby/1.9.1/net/smtp.rb:939:in `critical'
from /usr/lib/ruby/1.9.1/net/smtp.rb:552:in `do_start'
from /usr/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
from /var/lib/gems/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
from /var/lib/gems/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:2034:in `do_delivery'
from /var/lib/gems/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:229:in `block in deliver'
from /var/lib/gems/1.9.1/gems/actionmailer-3.2.6/lib/action_mailer/base.rb:415:in `block in deliver_mail'
from /var/lib/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in `block in instrument'
from /var/lib/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /var/lib/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in `instrument'
from /var/lib/gems/1.9.1/gems/actionmailer-3.2.6/lib/action_mailer/base.rb:413:in `deliver_mail'
from /var/lib/gems/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:229:in `deliver'
from mailer.rb:34:in `<main>''
Any help would be appreciated! Thanks in advance!
Upvotes: 3
Views: 3417
Reputation: 14913
Unless its a typo, the "domain" parameter is wrong.
:domain => 'google'
should be :domain => 'yourdomain.com'
Your code given below, with the correct domain works fine
require 'action_mailer'
class Mailer < ActionMailer::Base
def daily_names_email(names,subject="test daily mail",to = "[email protected]")
mail(
:to => to,
:from => "[email protected]",
:subject => subject
) do |format|
format.text
format.html
end
end
end
Mailer.raise_delivery_errors = true
Mailer.delivery_method = :smtp
Mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "yourdomain.com",
:authentication => :plain,
:user_name => "[email protected]",
:password => "*****",
:enable_starttls_auto => true
}
Mailer.view_paths = File.dirname(__FILE__)
Mailer.logger = Logger.new(STDOUT)
email = Mailer.daily_names_email('hello').deliver
puts email
Upvotes: 1