Hi @William Dias ,
I suggest you can use try-catch to handle exceptions. You can include codes that may cause an exception in a try block. If you send email failed ,it could for loop to send the email.
You can refer to the following code:
public void DownloadEmail(string email)
{
int tryAgain = 10;
bool failed = false;
do
{
try
{
failed = false;
var smtp = new SmtpClient();
var mail = new MailMessage();
const string mailBody = "Body text";
mail.To.Add(email);
mail.Subject = "Mail subject";
mail.Body = mailBody;
mail.IsBodyHtml = true;
smtp.Send(mail);
}
catch (Exception ex)
{
failed = true;
tryAgain--;
var exception = ex.Message.ToString();
//Other code for saving exception message to a log.
}
}
while(failed && tryAgain !=0)
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.