views:

79

answers:

1

I have a big problem with my SMTP server for sending emails. It's down often.

At this point I am using this code:

MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("[email protected]");
mailMsg.To.Add("[email protected]");
mailMsg.Subject = "...";
mailMsg.IsBodyHtml = true;
mailMsg.BodyEncoding = Encoding.UTF8;
mailMsg.Body = "Mail";
mailMsg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("[email protected]", "password");
client.Port = 456;         
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Send(mailMsg);

But, when my SMTP server is down I want to put all the emails in a queue and when it recovers I want to send them one a time. Is there any way how to do this programatically in C#?

+1  A: 

Gmail's SMTP server is down often ? That is strange.

If emailing is vital, I suggest you to use a local queuing service or build your own based on Microsoft Queuing system.

But if it's so vital, I would try to solve my SMTP problem instead.

Pierre 303
Gmail SMTP was just an example. I am using that code with Gmail SMTP because it works and it's never down. The problem is with local SMTP, that's why I need a C# way to put messages in a queue when server is down...
Jeff Norman
@jeff If you use IIS as a the SMPTP take a look at MSMQ, send your messages to the MSMQueue instead of directly to SMTP-server. It is already in the system (or needs to be installed), only needs a small adjustment in the code ;)
Caspar Kleijne
Caspar is right, writing in the queue instead of connecting to the service can help. Just store the full email with headers and so on in the spool directory.
Pierre 303
And assuming that I use Gmail SMTP Server, how can I store the emails in queue first and then send them?
Jeff Norman
By maintaining your own queuing system. I suggest you the free queuing system available in this project: http://mailsystem.codeplex.com
Pierre 303