方法一:
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => "username", # 不需要加@gmail.com
:password => '', # 使用单引号
:authentication => :plain,
:enable_starttls_auto => true
}
出错:Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first. 23sm1922646pzk.0
解决:
需要安装smtp-tls gem
sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com
方法二:
I found a simpler way to send a mail through gmail. No configuration required.
step 1: gem install gmail_sender
step 2: in your app create a method in any controller and write:
require 'rubygems'
require 'gmail_sender' (if you are using rby version 1.8.6, then also install tlsmail)
def sendGmail
g = GmailSender.new("gmail_account_user_name", "gmail_account_password")
g.attach('/path/to/document.hz') # you can attach any number of files, but there are limits for total attachments size
g.send("someone@domain.com", "The subject", "The mail body")
end
And that's it!!!! Calll the sendGmail method and you are done.