Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, check if email was sent or not

I have an app that sends email to registred users. This app sends an automatic email to the user while he is using some functions. Plus, on the admin screen, the admin can send emails to all persons that didn't get the email sent automatically for any reason. I store in database a value showing if the email was delivered or not, so the admin won't send emails to someone that already got one.

The problem is: how can I check if the email was delivered correctly in order to update this value? I am not talking about tests, I need to check right after the method deliver is called if the email was sent, or if any problem happened, like connection loss or email is invalid. Is there any method or way to do this?

Thanks.

like image 314
Arthur Wilson Avatar asked Oct 26 '11 13:10

Arthur Wilson


1 Answers

When you send a message and no error is raised, you can assume that the mail was delivered (at least you can assume that some system accepted the responsibility to deliver your message).

Nevertheless, there are many reasons for delivery failure; sometimes you may get an error hours or even days later. You will need to have a bouncing mail address and inspect returned messages. If you want to process bouncing, inspect an open source software with bouncing treatment such as phplist. This is no so trivial as you might think.

Another alternative is send e-mails through a dedicated service such us SendGrid. This services provide APIs that will allow you to retrieve information about your messages.

like image 141
Paulo Abreu Avatar answered Oct 12 '22 11:10

Paulo Abreu