Rails ActionMailer 发不出去邮件

hegwin · 2012年04月12日 · 最后由 prothro 回复于 2013年07月30日 · 4981 次阅读

最近要做一个找回密码的功能 但是发送的邮箱要用公司的邮箱 公司的邮件服务器是 exchange…… 开了 SMTP,SSL 登陆

之前设置 action_mailer 用 163,gmail 都可以发的,唯独公司这个邮箱发不出去

我已经让管理员把我的邮箱账户权限提升到管理员了还是没用

config.action_mailer.smtp_settings = {
  :tls => true,
  :enable_starttls_auto => true,
  :address => "10.110.10.2",
  :port => 25,
  :domain => "domain.com",
  :authentication => :login,
  :user_name => "name",
  :password => "password"
}

这样设置的话 报错如下: OpenSSL::SSL::SSLError in UserController#lost_password hostname was not match with the server certificate

如果把

:tls => true,
:enable_starttls_auto => true,

这两行去掉

报错就会变成 Net::SMTPFatalError in UserController#lost_password
550 5.7.1 Client does not have permissions to send as this sender

另外……我隐隐的预感和证书有什么关系,smtp 里能指定证书吗?

就是证书的问题,怎么装单独一个证书我也不懂,可以围绕 ruby openssl certificate 搜搜一下

或者不安全的把校验关掉 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

class MailTool < ActionMailer::Base

def welcome_email(user, company) @user = user delivery_options = { :user_name => company.smtp_user, :password => company.smtp_password, :address => company.smtp_host } mail(:to=> @user.email, :subject=> "Please see the Terms and Conditions attached", :delivery_method_options=> delivery_options) end

end

当我调用 welcome_email 的时候出现参数不匹配,是版本问题??搜索了好多,都不能解决

需要 登录 后方可回复, 如果你还没有账号请 注册新账号