Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Actionmailer giving trouble! Mails sent acc. logs, not received...
5 Posts
Actionmailer giving trouble! Mails sent acc. logs, not received...

Hi Amit, basic steps are:

1 - Install action_mailer_tls:

./script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git

or

ruby script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git (in Windows)

2 - set up the account in environment.rb. My setup is only the following (similar of Sugiarto's setting):

  config.action_mailer.smtp_settings = {
  :tls => true,
  :address => 'smtp.gmail.com',
  :port => '587',
  :domain => 'mydomain',
  :authentication => :plain,
  :user_name => 'my_email',
  :password => 'my_password' 
  }

3 - Create a model to send the mail, for example:

class Notifier < ActionMailer::Base

  def notify(customer,sent_at = Time.now)
    subject    'Notification to customer'
    recipients customer.email
    from       'my_email'
    sent_on    Time.now
    
    body[:customer] = customer 
    
    part :content_type => "text/html" ,
    :body => render_message("notify" , :customer => customer)
  end
end

4 - have a template with the contents of email, eg:

in app/view/notifier/notify.html.erb

Test of Email 
Dear Customer:
This email is for.....

5 - Deliver the email, using for example deliver

Notifier.deliver_notify(customer)

I hope it was useful.

Regards

Person
Forum Rating: 100
Sign In To Rate Post

I just want to show my config to you:

require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)

  ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "xxx.com",
    :user_name => "xxx@gmail.com",
    :password => "xxx",
    :authentication  => :login,
    :tls => true
  }

this is my mailer

class Emails < ActionMailer::Base default :from => "Cobboc " def inviteApplied(recipient)

@account = recipient
mail(:to => recipient.email, :subject => "Invite Application received", :content_type => "text/html")

end end

these are my settings for using gmail

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {

:address => "smtp.gmail.com",
:port => 587,
:domain => "mysite.com",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true

}

i also added these lines to the environment file, development.rb

config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true

Hi Amit, Gmail uses TLS. Are you using some plugin?

You can try "action_mailer_optional_tls":http://douglasfshearer.com/blog/gmail-smtp-with-ruby-on-rails-and-actionmailer (the same resource in "github":http://github.com/collectiveidea/action_mailer_optional_tls/ ). It is easy to use. Just install the plugin and configure it in environment.rb, as explained in the documentation.

Ifi t's not the issue, can u post some code, so we can help?

Regards

Fernando

Person
Forum Rating: 100
Sign In To Rate Post

Hi,

I a trying to send an email with actionmailer and smtp... I am using gmail for smtp to ensure delivery to inbox. I defined the settings in the config block in config/application.rb

the function looks like

def SendEmail(rec) @acc = rec mail(:to => rec.email, :subject => "U got mail!", :content_type => "text/html") end

i also added a default :from => "me@me.com" above the function

now when the method is called, the logs say the email was sent, but i never receive an email... ne idea what is going wrong?

5 Posts
Login to add your message