This is an strange problem,
At first I could send my mail via mailgun,
But now the expected recipient bill.email will be replaced with me##{ENV['mailgun_domain']}
I totally have no idea. because the code not changed
class BillMailer < ActionMailer::Base
default from: "me##{ENV['mailgun_domain']}"
def confirm_bill(bill, cart)
mail(to: bill.email, cc: "poc7667#gmail.com")
end
end
I printed the mail object, everything looks fine
#<Mail::Message:70158682584200, Multipart: false, Headers: <From: balance#4am-lesson.com>, <To: test_123#gmail.com>, <Cc: test_123#gmail.com>, <Subject: hihi>, <Mime-Version: 1.0>, <Content-Type: text/html>>
But when I checked the mailgun log, my recipient was replaced with balance_coffe#sandboxc88b11b1bddf4594aad351f79e76d6ba.mailgun.org, it supposed be my default sent from, I thought it a mailgun bug
"message": {
"headers": {
"to": "balance_coffe#sandboxc88b11b1bddf4594aad351f79e76d6ba.mailgun.org",
"message-id": "20150503112244.C04DC5995993#Poc-MacBook-Pro-Retina-15-2013-late-2.local",
"from": "MAILER-DAEMON#Poc-MacBook-Pro-Retina-15-2013-late-2.local (Mail Delivery System)",
"subject": "Undelivered Mail Returned to Sender"
},
"attachments": [],
"recipients": [
"balance_coffe#sandboxc88b11b1bddf4594aad351f79e76d6ba.mailgun.org"
],
"size": 20919
},
"recipient": "balance_coffe#sandboxc88b11b1bddf4594aad351f79e76d6ba.mailgun.org",
"event": "accepted"
This is perfectly valid behavior. If you observe your from and subject attributes in your log, you'll see, your smtp server (OSX default) is trying to tell you about a failure mail delivery. This is what an SMTP server will do if it cannot deliver an email to the recipient.
To fix this, you'll need to configure SMTP setting for your rails app. Add the following in your config/environments/development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "MYDOMAIN.mailgun.org",
:user_name => "postmaster#MYDOMAIN.mailgun.org",
:password => "MYPASSWORD"
}
Replace :domain, :username and :password with your mailgun credentials.
Related
I am using Rails 5. I have the following configurations in my config/environments/development.rb and config/environments/staging.rb.
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: "localhost", port: 1025 }
When I call the method that sends email, I get the following output.
Rendering mailer/consolidated_s3_storage_report.html.erb
Rendered mailer/consolidated_s3_storage_report.html.erb (0.4ms)
Mailer#consolidated_s3_storage_report: processed outbound mail in 17668.1ms
=> #<Mail::Message:86763960, Multipart: true, Headers: <From: mcds#sheridan.com>, <To: mcds.support#sheridan.com>, <Subject: 2017 July - S3 Storage Report>, <Mime-Version: 1.0>, <Content-Type: multipart/mixed; boundary="--==_mimepart_595c962cc36fb_1be1b2198436941"; charset=UTF-8>>
But email is not delivered to my gmail. The 'from' address is 'default from' from which all other emails are sent. Please clarify why my emails are not delivered.
You seem to be using Mailcatcher. Mailcatcher doesn't deliver messages, its to prevent messages from delivering to the actual To email addresses but lets you check of the message is framed correctly. Developers use Mailcatcher in development enviroments to see if the emails are rendered as they expect them to look like without spamming the To email holder.
All the emails that are sent to Mailcatcher can be viewed in a web interface. Visit http://localhost:1080 on your computer, you should be able to see all the emails you send so far from the development environment.
Following is the configuration for send mail to gmail:
config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "user#gmail.com", #your gmail id
:password => "password", #your gmail password
:authentication => "plain",
:enable_starttls_auto => true
}
I got an rails 4 application with following mailer configuration:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'myhost.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.myhost.com',
:port => 587,
:domain => 'myhost.com',
:authentication => :login,
:enable_starttls_auto => false,
:tls => false,
:openssl_verify_mode => 'none',
:ssl => false,
:user_name => "myusername",
:password => "mypassword"
}
Every time i try to send an mail with an testing mailer setup:
class TestMailer < ActionMailer::Base
default :from => "noreply#myhost.com"
def welcome_email
mail(:to => "testmail#mymailaddress.com", :subject => "Test mail", :body => "Test mail body")
end
end
TestMailer.welcome_email.deliver
I got this exception:
ArgumentError: An SMTP To address is required to send a message. Set
the message smtp_envelope_to, to , cc, or bcc address.
Is it possible that i forget something to set.?
And i can't find an configuration option for "smtp_envelope_to"
The error message is not about the SMTP envelope, but about the sender:
An SMTP To address is required to send a message
the rest is just a generic message.
Something in your testmail#mymailaddress.com is not working.
Do you use a real, working address? If not, try with one.
If you use sidekiq+actionmailer. Be careful, while sending email using hash. I was doing something like this
MyWorker.perform_async("var1", {email: 'test#test.com', var2: 'test1234'})
I banged my head for couple of hours, why it is throwing the above error. Because in the perform_menthod hash[:email] is nil. You need to use hash["email"] to receive the email. I do not know, the reason. But it helped me to get rid of this error.
Is :to => 'testmail#mymailaddress.com' how it is in your failing environment? If it's not a hardcoded email address, do make sure that a variable containing the to-address is not blank.
You don't have to set Mail::Message#smtp_envelope_to explicitly. It can guess it from its recipients, ie. Mail::Message#destinations (to + cc + bcc), but it doesn't seem to have any.
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:
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 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.
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.
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.
I'm getting this error in production when trying to create a user (i'm using the devise gem).
EOFError (end of file reached):
I hit this problem before and it was due to my smtp settings using zoho mail.
I believe my configuration below is what fixed the problem:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:domain => 'example.com',
:user_name => 'user#example.com',
:password => 'password',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
Now we've added SSL to the site and I believe that is what is causing this error to occur now.
Does anyone have any insight into this error or zoho mail smtp settings with SSL?
This error was caused by not having my config/initializers/devise.rb specifying the correct email address for config.mailer_sender.
Also! I made this additional mistake and had the same issue: I used my own domain instead of the mail server domain for the "domain" variable.
Your environment variable should be:
GMAIL_DOMAIN=gmail.com
Or for the example above:
:domain => 'gmail.com',
I found one cause for the error here => https://stackoverflow.com/a/40354121/6264112
But this didn't solve my issue. While I wasn't getting any errors, my emails were still not working through Zoho so I found another solution that works perfectly for my needs...
1) Connect Zoho to gmail using SMTP. I setup my zoho email as an alias for my personal gmail account so zoho emails are forwarded to gmail and I can reply to them IN gmail FROM my zoho email address. This should be done anyways so you never have to login to zoho. Just do all emailing from gmail.
2) Connect ActionMailer to gmail account NOT zoho.
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:user_name => ENV["gmail_username"],
:password => ENV["gmail_password"],
:authentication => :plain,
:enable_starttls_auto => true
}
Now, I just need to specify the to and from values in the mailer like so:
def notify_admin (message_details)
#message_details = message_details
mail(to: "jesse#mydomain.com", subject: "Contact form filled out by: " + message_details[:name], from: message_details[:email])
end
This works when I want to send emails to myself as is the example above when someone submits the contact form.
It ALSO works when I want to send an email from my domain such as when they fill out the lead magnet. All I did was switch the to: and from: addresses.
Here's a working pony gem call.
Pony.mail({
:to => 'apotonick#gmail.com',
subject: "Pony ride",
body: "Awesome!",
from: "nick#trb.to", # this MUST be the sending Zoho email.
:via => :smtp,
:via_options => {
:address => 'smtp.zoho.com',
:port => '465',
:enable_starttls_auto => true,
ssl: true,
:user_name => 'nick#trb.to', # MUST be identical to :from.
:password => 'yourStrongPw',
:authentication => :login,
}
})
I had this issue, and I tried everything and still couldn't figure out what the issue was.
Let's face it, it's a SH!t message. What I did find though I was running my rails app locally with POW and its actually a POW error.
When I run rails server and do the same thing that caused the error, I actually got the real error message and was able to find I hadn't setup my controller correctly
I am trying to send email using sendgrid. The email is delivered, but when i check it, the content is missing.
I followed the instruction provided by sendgrid.
-config.action_mailer.delivery_method = :smtp
-edit config/environment.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => '25',
:domain => "halo.dev",
:authentication => :plain,
:user_name => "account",
:password => "password"
}
The email can be successfully delievered. However,it only shows
from halo#halo.net via sendgrid.me
to user#user.com
date Wed, Nov 2, 2011 at 5:23 PM
mailed-by sendgrid.me
signed-by sendgrid.me
No content html is shown
What I have tried:
deliever the email as file (i.e config.action_mailer.delivery_method = :file) It works fine. I got the file in local
deliever the email using the program itself (i.e. config.action_mailer.delivery_method = :sendmail) It works fine too. When I check the email, everything is ok.
Try turning on the Email Template App inside of your Sendgrid Account.