Rails ActionMailer发送没有身份验证的电子邮件

Edw*_*ndo 3 email ruby-on-rails

因此,我的一个项目有一个SMTP服务器,该服务器已配置为在没有任何形式的身份验证的情况下使用.这是我的SMTP设置config/environments/production.rb.

config.action_mailer.asset_host = 'http://example.com'
config.action_mailer.default_url_options = { host: 'example.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
    address:              'mail.example.com',
    port:                587,
    domain:               'info.example.com',
    user_name:            'no-reply@example.com',
    password:             '',
    openssl_verify_mode: 'none',
    authentication:       nil,
    tls:                  false,
    enable_starttls_auto: false
}
Run Code Online (Sandbox Code Playgroud)

我虽然authentication需要设置模式nil但是,当我尝试发送电子邮件时,它给了我这个错误.

2.0.0-p481 :001 > CustomerMailer.test.deliver
Net::SMTPAuthenticationError: 503 5.5.1 Error: authentication not enabled
Run Code Online (Sandbox Code Playgroud)

伙计们?

col*_*inm 6

您正在指定身份验证详细信息.ActionMailer将相应地使用它们.

解决方案:不要.

config.action_mailer.smtp_settings = {
    address: 'mail.example.com',
    port:    587,
    domain:  'info.example.com'
}
Run Code Online (Sandbox Code Playgroud)

(domain根据您的服务器配置,参数本身可能是不必要的.)