Mandrill send email ruby on rails - ruby-on-rails

Im using mandrill for sending email and it show for some emails that the email From: ma#mail133-28.atl131.mandrillapp.com [mailto:ma#mail133-28.atl131.mandrillapp.com] On Behalf Of info#****.com
in my name mailer default from: "info#****.com"
and in the development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:domain => 'www.****.com',
:user_name => '**#**.ca',
:password => '***',
:authentication => :plain,
:enable_starttls_auto => true
}
Why is that? i want to show from: info#****.com without this ma#mail133-28.atl131.mandrillapp.com [mailto:ma#mail133-28.atl131.mandrillapp.com] On Behalf Of info#****.com

From Mandrill KB
If your recipients use Outlook, Hotmail (and other Microsoft webmail
services), or Gmail, they may see an indication in the email that it
was sent by Mandrill on your behalf instead of just your 'from' name
and address. Add SPF and DKIM records to your sending domains to
remove the 'on behalf of' or 'via' information.
Instructions on how do that can be found here: https://mandrill.zendesk.com/hc/en-us/articles/205582277-How-do-I-add-DNS-records-for-my-sending-domains-

Related

Why can't I see any emails in my inbox sent from my Heroku Rails app using SendGrid SMTP Relay in development mode?

I'm trying to switch over to SendGrid from Mandrill in my Rails 4.2 app through SendGrid's SMTP Relay. I have set the 'To Email' to be my personal email address so that I can view the emails that have been sent, however none of the emails actually appear in my inbox despite the rails console claiming to have processed and sent the email.
I am fairly certain all my mailers have the appropriate smtp settings as I have mostly followed the instructions provided on the SendGrid website: https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
I have also tested my connectivity to SendGrid's SMTP Relay through telnet and the connection is succesful.
My SendGrid dashboard indicated that 0 emails have been sent. None of my emails appear under the Suppressions tab either so it's not like they have bounced or have been blocked.
This is in my config/environment.rb:
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
This is in my config/environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net' }
This is the line in my controller that calls my ApplicationMailer:
ApplicationMailer.send_email(user, 'mypersonalemail#email.com', 'Test Subject').deliver
And this is what gets printed in the console when the mailer method is executed:
ApplicationMailer#send_email: processed outbound mail in 789.9ms
Sent mail to mypersonalemail#email.com (103.4ms)
But I still don't get any emails in my inbox or spam folder. Does anyone know how I can solve this? Thanks in advance.
Your domain and host options are wrong. Use localhost:3000 (unless you're using docker or something at which point replace localhost:3000 with 0.0.0.0:8000)
#/environments/development.rb
#Mailer Options
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'localhost:3000',
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
config.action_mailer.asset_host = 'http://localhost:3000'
Make sure to add the sendgrid credentials to your local machine as environment vars. To get them, go to your heroku app and click on settings, then "reveal config vars". Then add those sendgrid credentials to your local machine as env. vars and you're done.

Action Mailer Not delivering Emails - MailCatcher and sendmail

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
}

Can I send email from different addresses using same ActionMailer

I'm using ActionMailer for my Rails 2.3.9 application.
When I send an email using:
deliver_user_invite
config:
def user_invite(subject, content)
subject subject
from "User Invite <invite#mydomain.com>"
recipients "invites#mydomain.com"
sent_on Time.now
content_type "text/html"
body :content => content
end
with SMTP configuration
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'mydomain.com',
:authentication => :plain,
:user_name => 'user#mydomain.com',
:password => 'password'
}
However when the email is sent, the sender email shows as user#mydomain.com instead of invite#mydomain.com.
Can I have different SMTP configuration for different email addresses? or Is there a way to set the sender email address from ActionMailer config?
This is a Gmail SMTP limitation. It will always make the sender of the e-mail be the username/login you use for your smtp settings, and will ignore your from address.
A possible workaround might be to change the smtp settings dynamically when you need to send as someone else.
Edit: You might be able to go into the settings for your own Gmail account and use the "Add another email address you own" option to allow your account to send through those e-mail addresses. I haven't tested it, but it might work. (See http://www.mobileread.com/forums/showpost.php?p=21093&postcount=1).

Net::SMTPAuthenticationError 502 5.5.2 in Rails ActionMailer

i'm trying to send confirmation email to the user.
But i get following error:
Net::SMTPAuthenticationError (502 5.5.2 Error: command not recognized
Configuration in production.rb is following:
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'path_to_address_specified_by_my_hoster',
:port => 25,
:domain => 'my_domain.com',
:authentication => :plain,
:user_name => 'signup#my_domain.com',
:password => 'password'
}
I have created a mailbox in user profile at my hosting provider, named "signup#my_domain.com"
For created mailbox, they issued to me login and password:
login = verbose_login
password = verbose_password
I did't completely understood the exact format of :user_name.
Should i use
:user_name => "signup#my_domain.com"
or:
:user_name => "signup"
or:
:user_name => "verbose_login"
Or this field is specific to the mail server, and i must ask support of hosting provider ?
And what the difference between :authentication => :plain and :login ?
Thanks.
This works well for me:
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'my_nick#gmail.com',
:password => 'secret_password',
:authentication => 'login',
:enable_starttls_auto => true
}
more info here
Petr
I have got the same error recently, and the reason was incorrect format of recipients
recipient = IO.readlines(emails_filename).first
mail(:to => recipient, :subject => subject)
Don't forget to add strip to get clean email addresses.
I had the same problem, but it is just a google configuration issue.
For some reason Google was blocking access from unknown location (app in production), so to solve this you can go to http://www.google.com/accounts/DisplayUnlockCaptcha and click continue (this will grant access for 10 minutes for registering new apps).
On the other hand, you could login to your gmail account, then go to https://www.google.com/settings/security/lesssecureapps and enable the access to less secure applications, which was the solution for me!
Please try to login with browser once.
There might be some issue with login (it will ask captcha etc).
Once you successfully logged-in, then try with Rails Mailer.
It should work now.
This issue generally happens with test account as we do not login via browser usually.
Then mail providers ask for confirmation like captcha, dob or answer of security question etc.
You've to use ActionMaliler::Base instead of config
ActionMailer::Base.smtp_settings #try this
config.action_mailer.smtp_settings #instead of this
Change your smtp code to below. It should work now.
ActionMailer::Base.smtp_settings = {
:address => 'path_to_address_specified_by_my_hoster',
:port => 25,
:domain => 'my_domain.com',
:authentication => :plain,
:user_name => 'signup#my_domain.com',
:password => 'password'
}

Delivery issues with Rails + Gmail SMTP in Dreamhost

I just released a Rails app in Dreamhost and I'm using Google Apps for my domain to handle Emai. I created the admin#domain.com account to serve as the sender authentication.
I installed smtp-tls plugin and my smtp conf is:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "www.domain.com",
:authentication => :plain,
:user_name => "admin#domain.com",
:password => 'secret'
}
The problem: Emails sometimes arrives, and sometimes don't. The recipient addresses are not exclusively Yahoo or GMail accounts, so I think it's not a spam issue. Any ideas? Thanks!
If you want better tracking of whether or not your emails are getting where you're trying to send them, checkout PostageApp:
http://postageapp.com/

Resources