sign in
Home | Updates | Pages | Users | Admin | Help

activegmail

ActiveMailer sending via GMail

Using GMail (smtp+ssl or tls) with Rails ActiveMailer (all credits going to entombedvirus ):

Send email with ActionMailer through TLS only SMTP server

So for Debian (Ubuntu):

Install msmtp (light SMTP client with support for server profiles)

$ sudo apt-get install msmtp

Create/edit ~/.msmtprc

account gmail
host smtp.gmail.com
auth on
user <your_account>@gmail.com
password <your_password>
tls on
tls_starttls on
from <your_account>@gmail.com
maildomain gmail.com
account default : gmail

Stop msmtp complaining about permissions

$ chmod 600 ~/.msmtprc

Add on the bottom of yourrailsapp/config/environment.rb (and comment another ActionMailer::Base.delivery_method settings if exists)

ActionMailer::Base.delivery_method = :msmtp

module ActionMailer
  class Base
    def perform_delivery_msmtp(mail)
      IO.popen("/usr/bin/msmtp -t -C /<path_to>/.msmtprc -a gmail --", "w") do
 |sm|
        sm.puts(mail.encoded.gsub(/\r/, ''))
        sm.flush
      end
    end
  end
end

Do not forget to fix the exact path to your .msmtprc in the source above.


Powered by JunebugWiki v0.0.31 Page last edited by stoyan on December 15, 2006 05:46 PM (diff)
[readonly] Version 2 (current) «olderversions