2013-08-18 134 views
5

我使用ActionMailer在我的应用程序中发送“联系我们”表单。
我使用山魈应用程序发送我的emails.These是我的设置:使用ActionMailer和Outlook/Mandrillapp SMTP服务器发送邮件

配置/环境/ 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应用程序API密钥。

应用程序/邮寄/ contactus_mailer.rb

class ContactusMailer < ActionMailer::Base 

    default :from => "[email protected]" 
    default :to => "[email protected]" 

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

end 

自定义域上述帐户的有效性 - example.com

以上的电子邮件帐户,即[email protected] & [email protected]的供应方式以及充分功能。以上帐户是在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"=>"[email protected]", "content"=>"Random body"}, "commit"=>"Send Message"} 
    Rendered contactus_mailer/new_message.text.erb (0.5ms) 

Sent mail to [email protected] (2679ms) 
Date: Sun, 18 Aug 2013 12:35:38 +0530 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]l> 
Subject: [WebsiteName] Dummy name - [email protected] 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

Name: Dummy name  
Email: [email protected] 
Body: Random body 

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

山魈应用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])\n\t(Authenticated sender: [email protected])\n\tby ip-10-31-147-25 (Postfix) with ESMTPSA id 6811A151A064\n\tfor <[email protected]>; Sun, 18 Aug 2013 08:19:11 +0000 (UTC)\nDate: Sun, 18 Aug 2013 08:19:11 +0000\nFrom: [email protected]\nTo: [email protected]\nMessage-ID: <[email protected]mail>\nSubject: [WebsiteName] Dummy name - [email protected]\nMime-Version: 1.0\nContent-Type: text/plain;\n charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\nName: Dummy name\n\nEmail: [email protected]\n\nBody: Random body", 
    "to": [ 
     "[email protected]" 
    ] 
} 

完全响应:

[ 
    { 
     "email": "[email protected]", 
     "status": "rejected", 
     "_id": "9c9f88c588ee4f369437b8dd5d531c8c", 
     "reject_reason": "soft-bounce" 
    } 
] 

山魈应用API日志开发环境:

Full Request for development env。与生产环境相似。但是,在开发过程中,回应是不同的。
完全响应:

[ 
    { 
     "email": "[email protected]", 
     "status": "sent", 
     "_id": "e67f31f893a84ecdb0ed2438e5741ce1", 
     "reject_reason": null 
    } 
] 

注:我不是在开发和生产环境让我的账户[email protected]电子邮件。
查询:

  1. 为什么我会得到拒绝的状态和软弹拒绝的理由进行生产ENV,而对于发展它说发送状态,并没有拒绝的理由。

  2. 为什么我在这两种情况下都没有收到邮件?

P.S.
最初,我没有使用Mandrill app,并且使用smtp.live.com作为我的SMTP服务器以及我的no [email protected]凭据,但这并未奏效。 然后,我在谷歌上进行了一些挖掘后转向了Mandrill。
如果有人可以帮助Outlook邮件设置,这将是同样好。这样,Mandrill就完全不需要了。

回答

2

我知道它有没有Mandrill。直到7天后,我才收到任何电子邮件,我的收件箱里充斥着我所有的测试邮件。

似乎我的DNS,我的电子邮件帐户的TXT记录有一个小故障,导致了延迟。

也尝试没有Mandrill,邮件得到正确发送。因此,在这里发布Outlook的设置。可能对其他人来说很方便。

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.live.com", 
    :port     => 587, 
    :enable_starttls_auto => true, 
    :user_name   => '[email protected]', 
    :password    => 'password', 
    :domain    => 'example.com', 
    :authentication  => 'plain' 
} 

注意:在生产中使用,设置raise_delivery_errors

+0

我正在使用此确切设置,并且出现ssl错误。你有没有ssl证书?为你的域名? –

+0

@TommyAdey:没有。我没有SSL证书。你能否请你多解释一下你的问题。 –

+0

Mine说OpenSSL :: SSLError - SSL_read:错误的版本号。我一直在尝试几天,但它仍然无法正常工作。我也尝试过:openssl_verify_mode =>'none'。 –

3

你有application.rbproduction.rb定义

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

?它应该设置为您的域名。我发现有些服务器会拒绝未明确定义主机名的邮件。

+0

谢谢,但这是我的TXT记录导致邮件延迟的暂时性问题。 –

相关问题