Verifying bounced email id in ruby on rails - ruby-on-rails

I am building an email app in ruby on rails and I had a basic version which just used to send emails using AWS SES but recently I received a mail from AWS team saying that most of the email which I have sent had bounced back and they will discontinue my account if I send emails to the bounced email ids.
Is there any way to verify before sending email to any address that whether that email exists or not and valid or not.
Any gem or work around will help me a lot

The general way to do this is purely from a system design point of view. If you are going to collect an email address from one of your users and send them email periodically, or as events happen etc, then you should first ask them to "verify their email address". This typically involves generating a unique token, putting that into your database, linked with the user, then sending an email containing a URL with that unique token in it. The user clicks the link, which goes to a controller in your Rails application that matches the token against the user. If they can't follow that link, they can't read your emails, so don't send further email to that address.
If you obtained the email addresses through "other means", you're down to setting a Return-Path address on the outgoing email (bounces will be sent here), then checking that mailbox for bounces. I'm also often suspicious of how people happen upon a list of email addresses that didn't come from users consenting to an agreement with your website.
You could use the Mail gem to do this, but you need to know how to set up an SMTP server that pipes the email into your Rails application, which is not straightforward without prior experience. You can also use a variable Return-Path address (VERP), such as <some unique hash>+bounces#your-domain.com, where <some unique hash> references the email address in your system. This takes away the pain of trying to parse and interpret the bounce email, since the address it is sent to tells you who the bounced recipient is.

Related

Rails ActionMailer: Contact form - getting the right headers

On our webpage we have a contact form to let people contact us without sharing our email addresses.
We require a name, an email address and a message and allow people to send a copy to themselves.
On our server we have Postfix setup to send outgoing email.
Right now we add information as:
from = their email
to = our email and theirs if they want a copy. (could be cc instead)
It works okay, but just some weeks ago Gmail started to put all our emails in junk, even with explicit rules and stuff.
We figured out our Message-ID have the wrong format and added
def set_message_id(sent_at: Time.zone.now)
headers["Message-ID"] = "<#{Digest::SHA2.hexdigest(sent_at.to_i.to_s)}#domain.com>"
end
Based on an article from Mailgun and StackOverflow.
However we also get an SFP-softfail because we send the email from the users email, and the domain of their email does not have the same origin as our domain.
How do you solve this? We really like the way that you can instantly respond to a contact email and get the right name and email address automatically.
Is it worth investing in a service such as Mailgun just for this contact form?

Automatically sending an activation key by SMS or email after registration

I'm working on a free iOS app; at the end of the registration (when the user has registered a good phone number and good email address) I want the user to enter a code which he has received on his phone or email.
But the problem is how to send automatically a SMS or an e-mail programmatically that contains the code?
I don't want the user to be redirected to a specific view controller to compose a message by himself (like with MFMessageComposeViewController or MFEmailComposeViewController)
just and only just the same appearance of SMS or email sent to users but with a different activation key (for the keys, I think about auto generated keys stored in a database).
And I think about the same way for forgotten identifiers, the user enter his email address or his phone number in a text field, and a message is automatically sent with the password and the username of the user, if the email address or the phone number entered is already existing in the database, if it is not, it shows an alert view with an error.
Does anyone have an idea for how to do this?
You can use the following services Parse.com + mailgun. Search on Parse.com for a tutorial using mailgun and it should accomplish what you are trying to do. On a side not, be careful when creating an app which does not allow the user to use it until they enter some access code, it is against the Apple rules and could lead to rejection.
I assume you have a server that generates this activation code that is sent to the user.
When the user enters the text field with the code he got it should be sent back to the server with an http request (use NSURLConnection ). The server should response to the http request with approval or error whether the code is right, or send the username and password and any other data the user needs to continue.

Setting default from address of email in ios

In my app, there is an email functionality which should send email from an id, which is not configured with mail app. From address will be like noreplyATgmail.com .. some thing like that.
How can I hard code the from address of an email ?
It's impossible to send email from account where user isn't authorised in.
For your aims it's better implement email functionality on server side that could be authorised to send emails from address that you specified.
As per my comment - you can't, you should use reply-to for that, or send a request to a server to send the email. The from gets set from the selected email address you eventually chose to send the email with.
For example:
mailto:email#email.com?subject=Subject&reply-to=noreply#something.com
I don't think there's anyway to do this using MFMailComposeViewController.

How to send emails using Amazon SES without verifying 'from' email address

Can we send emails from Rails application using Amazon SES SMTP service where sender's email ID is unverified.?
I know that Amazon SES can send emails to unverified addresses. Is there any way to send emails from unverified arbitrary email address.
I want to know that, is there any way to get rid of it because my application is sending emails using user's email addresses as sender's email address.
I got one solution for this problem. We can add arbitrary email address in From header of email along with the verified email address as follows
"arbitrarymail#example.com <verifiedemail#example.com>"
Because of this the receiver can get some Idea about the sender of the email.
Unfortunately, it's not possible to send emails from any arbitrary email address using Amazon SES without verification.
You can however verify an entire domain, so that emails can be sent on behalf of all senders from the verified domain. If all your senders email addresses originate from a single domain, this solution will work, otherwise you may need to consider using an alternative to SES.
Announcement here: http://aws.amazon.com/about-aws/whats-new/2012/05/15/amazon-simple-email-service-announces-domain-verification/

Rails, SendGrid - Forwarding mailer-daemon emails to user

I have an application that allows users to send an invitation to a friend. Emails are being sent out using SendGrid. I am wondering if it's possible to forward the mailer-daemon emails back to the user in an event they type in an email address that doesn't exist.
So for example a user enters in the email 'thisisnotreal#fakedomain1234.com' to send the invitation. I want to be able to notify the user that the email they have entered doesn't exist. Usually when you just send an email from an email client the server lets you know right away that the email is not able to be delivered. I am wondering if it's possible to do this as well through SendGrid.
Take a look at the event notification section of the SendGrid API. You can add a page to your application that accepts POST requests from SendGrid, and then you'll get event notifications in real-time.
When a bounce event is posted to that listener from SendGrid, you could then lookup the user that needs to be notified via the recipient email. If you don't have this relationship available in your local store, you could pass a unique argument to SendGrid at send time that contains information you can use for the lookup - unique arg information is included with event notifications. Then it's just a matter of taking the appropriate action required to notify your user - either with an email or via a notice on your website or a text message or whatever is best for your application.
This maintains asynchronous communication. You'll be alerted when something goes wrong without having to add blocking code, and you can send your users a nice branded message (using SendGrid, of course) rather than just forwarding a mailer-daemon response .

Resources