views:

302

answers:

2

Hi, I am developing a test application and running the whole thing on my work pc. I am using my corporate mail server to send mails. It works fine normally. I was wondering how to handle any conditions like if the mail server is not reachable from my pc. As far as i have read about it, the rails application just sends the mail and that's it. There is no way to know if the mail reached the recipient, if the recipient mail id was correct etc. Any thoughts on how to handle this scenario? Thanks and Regards, Anjali

A: 

I thought about this problem. My thought was to store the message into a separate model called "mailqueue" and then run a ruby script that will pull and delete a message from that mailqueue only if the corporate mail server is available (which I already have the code to do that, I believe). Of course, if there is a better way, I would welcome it as well.

Rilindo
A: 

I believe you're mixing together two problems here, those are quite unrelated really.

First problem - making sure that the email was accepted by the corporate mail server (that is mail relay in this case). To solve this you can either build a local queue of messages (store them in the database, queue server, whatever) - and send them with a separate worker process, that will pull each message from a queue, try to deliver it and delete it only if it was accepted by the mail relay.

Or, if you don't need low-level manual control of the process, you can set up a simple local mail server on your machine and instead if sending emails directly to your corporate mail relay, just give them to your local mail server. It will then make sure that the emails were delivered to the corporate properly.

But in both cases you won't get any info about where the message was delivered to the final recipient - like whether the email address was valid, user's mailbox was not full, etc.

Second problem - track mail delivery errors. To properly and completely solve this problem you need to catch all mail bounced back to you from the remote servers and analyze it, as many errors are unknown at the moment when the email is send - but they come back later in the form of mail bounces. If you catch and track these bounces you'll be able to catch errors likefull mailboxes, invalid emails, just temporarily delivery failures, etc.

It's the way it is done in mail lists management software - for example, phpList operates in exactly the same way.

morhekil