我使用ActionMailer和action_mailer_optional_tls插件通过Gmail发送邮件。
这是我的设置:
class InstantMailer < ActionMailer::Base
layout "email"
def support(ticket)
@recipients = "support@domain.com"
@from = ticket.email #this is the user's email
@subject = "[#{ticket.category}] #{ticket.subject}"
@sent_on = Time.now
@body[:ticket] = ticket
content_type "text/html"
end
end
环境:
# Mailer Settings
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "domain.com",
:authentication => :plain,
:user_name => "account@domain.com",
:password => "***"
}
当我从服务器向用户发送邮件时,此方法正常。
但是,当用户填写联系表单时,来自字段仍然是account@domain.com,而不是用户的电子邮件。有什么问题?
答案 0 :(得分:3)
Gmail不允许使用已注册的邮件地址中继邮件...
答案 1 :(得分:1)
我将发送方式更改为:sendmail,它开始为我工作: - )
ActionMailer::Base.delivery_method = :sendmail