Emails sent from postfix via a Rails app are getting sent to spam in gmail - ruby-on-rails

When using 'mail' command to send email to a gmail user, the email goes through fine. When sending an email using a Rails app, the email is sent to the spam folder for the gmail user. Can someone help me think through this?

Emails landing in SPAM can happen due to many reasons:
Wrong Mail Server setup: Checkout here on how to setup
Email content: Content of the email can also invite SPAM. Sites like SpamCheck helps to check whether the content of the email is ok.
As mentioned by #Noli above, using services like Sendgrid, Critsend etc for sending out emails, chances of landing them in Inbox will be more. You can use them as relay servers from Postfix. But the first two steps are anyway necessary.
Use Mailchimp if you want to sent emails to many people, for eg: for sending out newsletters, marketing emails etc.

Mail deliverabillty is extraordinarily hard to get right. You should consider leaving this to the specialists like Sendgrid or Mailchimp, and not spend tooooo much development time thinking about it

Another thing to check is that if this is a new server, you may need to set up Domain Keys to authenticate to Gmail. This happend to me and I was able to get my mail removed from the spam folder by following these:
https://help.ubuntu.com/community/Postfix/DomainKeys
https://help.ubuntu.com/community/Postfix/DKIM

Related

Ruby on Rails app fetch bounces How to?

is there any possibility to check with the ActionMailer mail function if a mail-address is still alive?
My problem is that I have a ruby on rails application with lots of users, but some of those changed their mail address and now I got lots of mails back. It would be cool If I can check if the mail is still present, and if not I delete the user from Database.
Any Ideas for this problem?
If you're sending mail and it fails, you can view those if you've configured
raise_delivery_errors = true
That would go in your config/environment/development or production.rb
Sadly though, with raise_delivery_errors there's a gotcha:
This only works if the external email server is configured
for immediate delivery.
If you have the option to use something like mailchimp, sendgrid, etc it handles most of this for you - it won't send to bogus emails, it silences them on future mailings and is just a convenient way to manage your email clickthroughs, etc. Some email services give you a webhook that says "this email bounced" which you can then do something with in your app/database. Or more primitively, you can download a csv periodically from their portal and update the database.

Emails not going from Mandrill to Gmail

I'm trying to send email from my app, emails seem to be going to mandrill correctly and there getting delivered, but I see nothing in my inbox.
I've even tried sending them through my domain and I'm still not getting them. I get them from my live website its using gmail but I want to switch
Using mxtoolbox.com I found
SMTP Reverse DNS Mismatch and
454 4.7.1 Relay access denied which could mean its been marked for spam?
It's sent through emails twice so I'm wondering if theres a time between emails sent or something.
When I was testing this I thought my emails where being dropped by gmail. I found that for some reason there was a very long lag going from Mandril to Gmail. I received all my tests about an hour after Mandril sent them. Hope this helps someone stuck like I was.
Found this question trying to diagnose my issue.
I am using Mandrill and found that sending emails from Mandrill to Gmail will take anywhere from 10 seconds to 15 minutes. Can't establish a reason why sometimes it takes longer.
Mandrill blocks certain domains from being the send address to prevent fraud, but as long as you're sending from an address you know exists to an address you know exists, you should be fine. Also, if that were the problem, the email would bounce rather than send. Also, some email services have policies that prevent you from doing things like sending an email to your address from your address from an external service. Based on that error message you provided, it could be something like that; I would check your provider's policies (and your spam folder).
Not an answer but if you look on your mandrill Outbound activity page and click on the green icon that says Delivered you should see that it says No smtp events.
I don't know why it doesn't send but this show that it hasn't sent.
Or should I say hasn't arrived where it was supposed to.
Update:
On further investigation I found out that the emails weren't sending because I was using my personal email address as the sender from_email: When I changed this to a more business sounding email address it worked. So make something up if you have to, like no-reply#nonsense.com

Is there a way to setup a fake email inbox to check that email messages are being sent in ruby on rails?

I'm testing several user accounts and don't want to setup different emails to test with. All I need to know is if the email has been sent from my app successfully.
Is there a way to setup a fake email inbox to check that email messages are being sent in Ruby on Rails?
Set up MailCatcher:
MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.
This does several useful things for you:
Not only can you see that email is being sent but you can look at the email (text and HTML parts) as well.
You won't have to worry about spamming anyone as all the email your application sends goes straight to MailCatcher.
You won't have to worry about setting up a bunch of real email accounts anywhere, MailCatcher doesn't care what the addresses are, it just grabs the email and shows it to you.
Most importantly, your application doesn't have to change to use it, you just set up the appropriate SMTP values and away you go. This means that you're not running different code paths for your email handling in development, testing, and production and that means fewer bugs and late night disaster calls.
During development and testing, emails are also shown on the console. That has always been enough for me – I don't doubt rails' ability to actually send it once it's in production.

How can I integrate internal messaging with emails in asp.net?

in github when a user sends you a message two things happen. You get a "new Message" on your github dashboard and you receive an email.
if you reply to that email it triggers a new Github message internally... so the users can actually have a full conversation through their email client without going into github even though Github is managing it all.
I know Malgun/Sendgrid have apis to manage receiving of emails (they send a POST request to your app when an email is received) but I need a little more info on how to do it... how exactly can I set up my app so that when a user receives a message they can just hit reply on their favorite email client while still maintaining track of that conversation. (they can still check their messaging history through my site)
Does anyone have an idea how exactly they do it?
Please help.
How this is implemented really depends on how you can handle incoming messages. If you're able to receive your emails as a POST to your application, then the email is really no different to a user sending the message on your site, you just need to parse the From: header from the email, and look up the user, and strip the fluff out of the email.
If you're writing your own code to handle the emails (eg. that polls a mailbox), then you could just POST them over to your app in the same way, or parse them up and POST more structured data.
Once you have the data, it's easy to construct a message and write it to your DB (and fire off email notification to the user, remembering to set the Reply-To: or From: headers so your script gets the replies). Most of these kind of messaging systems don't keep track of conversations/threads, but just store a string subject (and use "Re: ...") to keep things simple, though you could obviously add this if you're feeling ambitious!
If you're doing this, you should be security in mind - malicious users may POST to your email script, and email headers can easily be forged. Spammers will also use any possible scripts they can find to relay mail through other peoples servers.

Most reliable way to deliver emails from a users email address in rails?

I would like to allow users to send emails which are generated in my rails app from their email address .
I know I can just use my servers sendmail, and set the from address to their email address, but there is a high chance the emails will be marked as spam.
Is there a better way to do this? Can I use sendgrid, or Amazon SES or make the user input their own SMTP details.
Any suggestions or best practices would be much appreciated.
This will fail in the face of SPF. SPF is essentially a way for a domain to say "email purporting to be from this domain will only be sent from these servers", so if you send email from a user at that domain from your server, anyone who does an SPF-check is likely to mark your mail as spam.
Essentially: Don't use the From header if the mail's not from the sender, use the Sender header instead.
I believe SendGrid support customising the From address. Heroku provide them as an add-on and they advertise "Complete control over the From: address." on their add-ons page
Amazon SES is out of the question for this use case: they require an authorization procedure before sending as a certain email address.
Even if you prompted them for SMTP server details, that's going to set off huge red flags to any competent users. Most SMTP servers are properly configured to either require authentication during the SMTP transaction, or require a recent POP3 or IMAP connection, and that means gathering user credentials. Do you feel like asking your users to trust you with their email password?
Overall, this is actually an astoundingly bad idea, especially considering email authorship proving techniques like SPF / Sender ID. Mails sent this way through non-authorized servers are increasingly likely to get (rightfully) flagged as spam.
Would your use case allow the mails to be "From" your application, but have a "Reply-To" of the user?

Resources