I am using ActionMailer
to send mails for a 'Contact Us' form in my application.
I am using Mandrill app for sending my emails.These are my settings:
config/environments/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'
}
config/environments/production.rb
I have removed the lineconfig.action_mailer.raise_delivery_errors = true
and changed the password for production - which is Mandrill app API key for production.
app/mailers/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
Validity of the above accounts on custom domain - example.com
The above email accounts i.e [email protected]
& [email protected]
are provisioned and fully functional. The above accounts are setup at Outlook.com and I have also double-checked the MX records for my domain example.com and the domain settings are Active for my domain. As a proof, I can send/receive emails on both accounts from the accounts.
Development and Production environment Logs:
When I use the Contact Us form in both environments, ActionMailer reports no errors and redirects successfully to Home page.
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: <52107242dbf6c_12a7f3fd8b1835ad03979@Jatins-MacBook-Pro.local.mail>
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)
Mandrill App API log for Production environment:
Full Request:
{
"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: <5210837f5ce24_26e56b87992f@5c11fd99-5533-4855-af78-40e02c939412.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]"
]
}
Full Response:
[
{
"email": "[email protected]",
"status": "rejected",
"_id": "9c9f88c588ee4f369437b8dd5d531c8c",
"reject_reason": "soft-bounce"
}
]
Mandrill App API log for development environment:
The Full Request for development env. is similar to the production environment. However, in development the response is different.
Full Response:
[
{
"email": "[email protected]",
"status": "sent",
"_id": "e67f31f893a84ecdb0ed2438e5741ce1",
"reject_reason": null
}
]
NOTE: I am not getting email on my account [email protected]
in both development and production environments.
Queries:
Why am I getting rejected status and soft-bounce reject reason for production env., whereas for development it says sent status and no reject reason.
Why am I not receiving any mails in both the cases?
P.S.
Initially, I wasn't using Mandrill app
and was using smtp.live.com
as my SMTP server along with my no [email protected]
credentials, but that didn't work out.
Then I switched to Mandrill after some digging on Google.
It'd be equally good if someone can help with the Outlook mail setup. That way, Mandrill won't be required at all.
I got it working with and without Mandrill. I didn't get any emails until 7 days later, my inbox was flooded with all my test emails.
Seems there was a glitch with my DNS, TXT records for my email account, which had caused the delay.
Also tried without Mandrill, and the mails are getting sent properly. So, posting the settings for Outlook here. Might come handy for someone else.
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'
}
Note: For use in production, set raise_delivery_errors
to false.
Do you have
config.action_mailer.default_url_options = {
:host => 'YOUR_HOST_NAME_HERE'
}
defined in application.rb
or production.rb
? It should be set to your domain name. I've found that some servers will reject mail without an explicitly defined hostname.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With