【问题标题】:Sending email issue in Amazon EC2 with Rails App [closed]使用 Rails App 在 Amazon EC2 中发送电子邮件问题 [关闭]
【发布时间】:2014-03-23 19:27:09
【问题描述】:

我的目标:电子邮件表单页面 - 如果用户按下发送,它必须将电子邮件发送到管理员帐户

好的,我遵循了 Rails 教程。

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'google.com',
    user_name:            'MYACCOUNT',
    password:             'MYPAASSWORD',
    authentication:       'plain',
    enable_starttls_auto: true  }
  # Print deprecation notices to the Rails logger.

这样设置,

而且效果很好!在我的本地主机中

但如果我部署到亚马逊 ec2。它不起作用,但 nginx 服务器日志显示没有错误:(

Processing by IndexController#send_email as */*
App 2705 stderr:   Parameters: {"contactName"=>"asfsdf", "email"=>"asdf@asdf.net", "comments"=>"asdf", "submitted"=>"true"}
App 2705 stderr: 
App 2705 stderr: Sent mail to MYEMAIL@gmail.com (10.9ms)
App 2705 stderr: Date: Sat, 22 Feb 2014 01:49:08 +0000
App 2705 stderr: From: asdf@asdf.net
App 2705 stderr: Reply-To: asdf@asdf.net
App 2705 stderr: To: MYEMAIL@gmail.com
App 2705 stderr: Message-ID: <53080214b6e70_aa42499f8854356@ip-172-31-23-192.mail>
App 2705 stderr: Subject: asfsdf***** MAIL FROM MY SITE******
App 2705 stderr: Mime-Version: 1.0
App 2705 stderr: Content-Type: text/plain;
App 2705 stderr:  charset=UTF-8
App 2705 stderr: Content-Transfer-Encoding: 7bit

我认为这不是代码问题,因为这在我的本地运行良好

我认为我必须在 ec2 中的某个位置设置配置

你能帮我解决这个问题吗?谢谢。

【问题讨论】:

    标签: ruby-on-rails email amazon-web-services nginx amazon-ec2


    【解决方案1】:

    这里有很多潜在的问题:


    生产

    您的development.rb 中有您的 SMTP 设置(有问题的详细信息)吗?这意味着它们仅在您的应用程序在开发环境中运行时注册

    这是一个常见错误,可以通过在config/environments/production.rbconfig/application.rb 中应用相同的代码来解决


    SMTP

    某些服务(Heroku 就是其中之一)强烈鼓励在您的应用程序背后使用第三方“事务性”SMTP 服务。值得注意的是,SendGridMandrill 是最受欢迎的两个

    这是我们与 SendGrid 和 Heroku(亚马逊)一起使用的工作代码:

      #config/environments/production.rb
      config.action_mailer.smtp_settings = {
        :address        => 'smtp.sendgrid.net',
        :port           => '587',
        :authentication => :plain,
        :user_name      => ENV['SENDGRID_USERNAME'],
        :password       => ENV['SENDGRID_PASSWORD'],
        :domain         => 'heroku.com',
        :enable_starttls_auto => true
      }
    

    发送

    另一个问题可能是您发送消息的方式

    许多系统(Heroku 就是其中之一)都有超时时间。这很重要,因为这意味着如果您的电子邮件发送时间超过超时时间,服务器将自动终止该进程

    更强大的方法是使用Resque &amp; Redis 之类的东西来排队电子邮件,确保您不会让请求超时

    【讨论】:

      【解决方案2】:

      由于 IP 已被 Spamhaus 列入黑名单,最终用户可能会拒绝它。您不应使用 EC2 实例来发送电子邮件,而应使用 Amazon SES 之类的服务(每天不超过一定数量的 EC2 实例)或第三方供应商,例如 sendgrid 或 authsmtp。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-09
        • 2018-03-16
        • 2014-02-12
        • 2018-03-01
        • 1970-01-01
        • 2014-12-30
        • 2012-07-03
        • 2018-04-07
        相关资源
        最近更新 更多