Sending E-mail with Rails via Gmail (Spoiler Alert! this is for dummies)
Yes, Rails is super cool, everything is super easy, and so far I really fall in love with it. But why is it that hard to send an e-mail via Gmail !?!
So after messing up a couple of git branches, I finally get it work, yey!
Here are the steps:
- Watch the railscast about sending email
- Install the gem with TLS
sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com
#to the top of file
require 'smtp-tls'
...
#to the very end of the file
ActionMailer::Base.smtp_settings =
{
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "dkberktas",#not with @gmail.com
:password => "xxxyyyzzz",
:authentication => :plain,
:enable_starttls_auto => true
}
script/generate mailer user_mailer
def registration_confirmation()
recipients "xxx@gmail.com"
from "xxx@gmail.com"
subject "Thank you for being that awesome"
body "no I am just kidding" #if you want to pass parameter do it like this -- > ":user => user"
end
#in application controller
def mailDeneme
UserMailer.deliver_registration_confirmation()
render :text => "OK"
end
#in routes.rb
map.mail '/mail', :controller => 'application', :action => 'mailDeneme'
If you see an error like this:
Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first.
You miss the item above about installing smtp-tls gem. Read it again again, or check this forum post.
ps. This is the official rails guide.
ps2. this is another link.
No comments yet





