加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用ActionMailer和Outlook / Mandrillapp SMT

发布时间:2020-12-16 23:08:37 所属栏目:百科 来源:网络整理
导读:我正在使用ActionMailer在我的应用程序中发送“联系我们”表单的邮件. 我正在使用Mandrill应用程序发送我的电子邮件.这些是我的设置: 配置/环境/ development.rb config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_erro
我正在使用ActionMailer在我的应用程序中发送“联系我们”表单的邮件.
我正在使用Mandrill应用程序发送我的电子邮件.这些是我的设置:

配置/环境/ development.rb

config.action_mailer.perform_deliveries = true 
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.mandrillapp.com",:port                 => 587,:enable_starttls_auto => true,:user_name            => 'SMTP username i.e Mandrill a/c username',:password             => 'API key for development',:domain               => 'example.com',:authentication       => 'plain'
  }

配置/环境/ production.rb

我删除了这条线
config.action_mailer.raise_delivery_errors = true
并更改了生产密码 – 这是用于生产的Mandrill app API密钥.

应用程序/邮寄者/ contactus_mailer.rb

class ContactusMailer < ActionMailer::Base

  default :from => "noreply@example.com"
  default :to => "help@example.com"

  def new_message(message)
    @message = message
    mail(:subject => "[WebsiteName] #{message.name + " - " + message.email}")
  end

end

以上帐户对自定义域的有效性 – example.com

以上电子邮件帐户,即noreply@example.com& help@example.com已配置且功能齐全.以上帐户是在Outlook.com上设置的,我还仔细检查了我的域example.com的MX记录,域名设置对我的域名是有效的.作为证据,我可以从帐户发送/接收两个帐户的电子邮件.

开发和生产环境日志:

当我在两个环境中使用“联系我们”表单时,ActionMailer不会报告错误并成功重定向到主页.

Started POST "/contact" for 127.0.0.1 at 2013-08-18 12:35:37 +0530
Processing by MessagesController#create as HTML
  Parameters: {"utf8"=>"?","authenticity_token"=>"UNgMrA04yk4sIbqtXjlLvLvDINgrBT5eP0wMSRYNgPs=","message"=>{"name"=>"Dummy name","email"=>"abc@pqr.com","content"=>"Random body"},"commit"=>"Send Message"}
  Rendered contactus_mailer/new_message.text.erb (0.5ms)

Sent mail to help@example.com (2679ms)
Date: Sun,18 Aug 2013 12:35:38 +0530
From: noreply@example.com
To: help@example.com
Message-ID: <52107242dbf6c_12a7f3fd8b1835ad03979@Jatins-MacBook-Pro.local.mail>
Subject: [WebsiteName] Dummy name - abc@pqr.com
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Name: Dummy name    
Email: abc@pqr.com
Body: Random body

Redirected to http://localhost:3000/
Completed 302 Found in 3841ms (ActiveRecord: 0.0ms)

适用于生产环境的Mandrill App API日志:

完整要求:

{
    "from_email": null,"from_name": null,"async": false,"key": "API key for production","raw_message": "Received: from example.com (unknown [23.20.245.109])nt(Authenticated sender: key_production@gmail.com)ntby ip-10-31-147-25 (Postfix) with ESMTPSA id 6811A151A064ntfor <help@example.com>; Sun,18 Aug 2013 08:19:11 +0000 (UTC)nDate: Sun,18 Aug 2013 08:19:11 +0000nFrom: noreply@example.comnTo: help@example.comnMessage-ID: <5210837f5ce24_26e56b87992f@5c11fd99-5533-4855-af78-40e02c939412.mail>nSubject: [WebsiteName] Dummy name - abc@pqr.comnMime-Version: 1.0nContent-Type: text/plain;n charset=UTF-8nContent-Transfer-Encoding: 7bitnnName: Dummy namennEmail: abc@pqr.comnnBody: Random body","to": [
        "help@example.com"
    ]
}

完整回复:

[
    {
        "email": "help@example.com","status": "rejected","_id": "9c9f88c588ee4f369437b8dd5d531c8c","reject_reason": "soft-bounce"
    }
]

用于开发环境的Mandrill App API日志:

完整的发展要求环境类似于生产环境.但是,在开发过程中,响应是不同的.
完整回复:

[
    {
        "email": "help@example.com","status": "sent","_id": "e67f31f893a84ecdb0ed2438e5741ce1","reject_reason": null
    }
]

注意:在开发和生产环境中,我没有在我的帐户help@example.com上收到电子邮件.
查询:

>为什么我被拒绝状态和软反弹拒绝生产环境的原因,而对于开发它说发送状态而没有拒绝原因.
>为什么我在这两种情况下都没有收到任何邮件?

附:
最初,我没有使用Mandrill应用程序,并使用smtp.live.com作为我的SMTP服务器以及我的no reply@example.com凭据,但这没有用.
然后我在谷歌挖掘之后切换到了Mandrill.
如果有人可以帮助Outlook邮件设置,那也同样好.这样,Mandrill根本不需要.

解决方法

你有没有
config.action_mailer.default_url_options = { 
  :host => 'YOUR_HOST_NAME_HERE'
   }

在application.rb或production.rb中定义?它应该设置为您的域名.我发现有些服务器会在没有明确定义主机名的情况下拒绝邮件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读