How can I queue emails when the SMTP server is down?

I have a big problem with my SMTP server for sending emails. It often happens.

At this moment I am using this code:

MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("fromMail@example.com");
mailMsg.To.Add("toMail@example.com");
mailMsg.Subject = "...";
mailMsg.IsBodyHtml = true;
mailMsg.BodyEncoding = Encoding.UTF8;
mailMsg.Body = "Mail";
mailMsg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("account@gmail.com", "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 the queue, and when it is restored, I want to send them once. Is there a way to do this programmatically in C #?

+3
source share
1 answer

Does Gmail SMTP Server Shut Down Frequently? This is strange.

If email is vital, I suggest you use a local service or create your own Microsoft Queuing system.

, SMTP .

+2

Source: https://habr.com/ru/post/1765572/


All Articles