Question

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 line
config.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 => "noreply@example.com"
  default :to => "help@example.com"

  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 noreply@example.com & help@example.com 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"=>"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 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: key_production@gmail.com)\n\tby ip-10-31-147-25 (Postfix) with ESMTPSA id 6811A151A064\n\tfor <help@example.com>; Sun, 18 Aug 2013 08:19:11 +0000 (UTC)\nDate: Sun, 18 Aug 2013 08:19:11 +0000\nFrom: noreply@example.com\nTo: help@example.com\nMessage-ID: <5210837f5ce24_26e56b87992f@5c11fd99-5533-4855-af78-40e02c939412.mail>\nSubject: [WebsiteName] Dummy name - abc@pqr.com\nMime-Version: 1.0\nContent-Type: text/plain;\n charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\nName: Dummy name\n\nEmail: abc@pqr.com\n\nBody: Random body",
    "to": [
        "help@example.com"
    ]
}

Full Response:

[
    {
        "email": "help@example.com",
        "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": "help@example.com",
        "status": "sent",
        "_id": "e67f31f893a84ecdb0ed2438e5741ce1",
        "reject_reason": null
    }
]

NOTE: I am not getting email on my account help@example.com in both development and production environments.
Queries:

  1. 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.

  2. 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 reply@example.com 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.

Was it helpful?

Solution

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            => 'noreply@example.com',
   :password             => 'password',
   :domain               => 'example.com',
   :authentication       => 'plain'
 }

Note: For use in production, set raise_delivery_errors to false.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top