【问题标题】:Difficulty configuring SMTP server for sending email难以配置 SMTP 服务器以发送电子邮件
【发布时间】:2019-12-01 17:55:27
【问题描述】:

我想从我自己的服务器而不是 gmail 发送电子邮件,我很难配置环境文件。

当我使用 gmail 凭据时,我可以从我的开发计算机发送电子邮件

  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp

  host = 'mysite.com'
  config.action_mailer.default_url_options = { host: host, protocol: 'http' }
  Rails.application.routes.default_url_options[:host] = host

  config.action_mailer.perform_caching = false

  config.action_mailer.smtp_settings = { 
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'example.com',
    user_name:            ENV["GMAIL_USERNAME"],
    password:             ENV["GMAIL_PASSWORD"],
    authentication:       'plain',
    enable_starttls_auto: true }

这很好用。但是如果我尝试从我的服务器更改设置,我将无法连接。

  config.action_mailer.smtp_settings = { 
    address:              'mail.mysite.com',
    port:                 465,
    user_name:            ENV["MYSITE_USERNAME"],
    password:             ENV["MYSITE_PASSWORD"],
    authentication:       'plain',
    enable_starttls_auto: true }


The configuration for the emails on my server are:

-------------------------
Secure SSL/TLS Settings (Recommended)
Username: test@mysite.com
Password: Use the email account’s password.
Incoming Server: mail.mysite.com
IMAP Port: 993 POP3 Port: 995
Outgoing Server: mail.mysite.com
SMTP Port: 465
IMAP, POP3, and SMTP require authentication.
-------------------------

我可以使用上述设置通过 Thunderbird 连接到服务器,但我无法连接到 Rails。 我使用了正确的用户名和密码。 我不知道我做错了什么。

【问题讨论】:

    标签: ruby-on-rails email


    【解决方案1】:

    smtp_settings 地址必须来自电子邮件客户端,例如 Sendgrid 或其他。您当前正在指定自己的域 (mysite.com)。他们应该提供必要的凭据,以便您能够发送电子邮件。

    【讨论】:

    • 我有:它们在上面。我认为它与需要 SSL 的端口 465 有关,而我在开发中没有设置。
    • 当然,如果没有https,您将无法使用第三方服务。如果任何第三方服务接受此类请求,我将认真重新考虑使用此类服务​​。
    【解决方案2】:

    您需要一个服务来发送您的电子邮件,我建议您使用 sendgrid,它的配置非常简单,每月最多 2000 封电子邮件是免费的。并且不在您的环境变量中设置用户名和密码,在凭据文件中设置。

    ActionMailer::Base.smtp_settings = {
      :user_name => 'your_sendgrid_username',
      :password => 'your_sendgrid_password',
      :domain => 'yourdomain.com',
      :address => 'smtp.sendgrid.net',
      :port => 587,
      :authentication => :plain,
      :enable_starttls_auto => true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多