Sending email through Gmail SMTP with Merb
Monday 11/3/2008 – Category: Uncategorized
I was having email delivery problems while using Postfix (emails were getting caught by spam filters) so I decided to try using Gmail SMTP to send stuff off.
Initially I tried to follow a tutorial like this to get Postfix to relay to Gmail but there was a lot of footwork involved setting up certificates, etc...and I couldn't get it to work at the end.
Finally, after searching around the Merb wiki, I found that it's really a lot more simple:
Gmail SMTP
Install tls mail to enable SSL support (required by Gmail).
$ gem install tlsmailThen configure Merb Mailer to work with Gmail
in config/init.rb:
Merb::BootLoader.after_app_loads do dependency 'tlsmail' # Activate SSL Support Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) # Configure Merb Mailer Merb::Mailer.config = { :host => 'smtp.gmail.com', :port => '587', :user => 'user@gmail.com', :pass => 'pass', :auth => :plain } endThen to send mail:
m = Merb::Mailer.new :to => 'foo@bar.com', :from => 'bar@foo.com', :subject => 'Welcome to whatever!', :text => partial(:sometemplate) m.deliver!
Leave a Reply
Recent Posts
- Flickr Original updates
(Saturday 08/7/2010 – 7 Comments) - LED Light for iPhone 4
(Monday 06/28/2010 – 48 Comments) - WWDC 2010: Worth Every Minute
(Monday 06/14/2010 – No Comments) - Flickr Original for Safari 5!
(Wednesday 06/9/2010 – 26 Comments)
