See title. Since SmtpClient.Send has no return value, I want to know how I can be sure that the E-Mail was successfully sent.
Here is the code I have until now and it works fine (it is from google):
private void sendMail(string strToAddress, string strFromAddress, string strSubject, string strBody)
{
// new instance of MailMessage
MailMessage mailMessage = new MailMessage();
// Sender Address
mailMessage.From = new MailAddress(strFromAddress);
// Recepient Address
mailMessage.To.Add(new MailAddress(strToAddress));
// Subject
mailMessage.Subject = strSubject;
// Body
mailMessage.Body = strBody;
// format of mail message
mailMessage.IsBodyHtml = true;
// new instance of Smtpclient
SmtpClient mailSmtpClient = new SmtpClient("mail.lablabal.com");
// mail sent
mailSmtpClient.Send(mailMessage);
}
If there's an immediate error, SmtpClient::Send() will throw an exception. There's no way to "track" the email (unless there's some confirmation link to click or whatever). You won't keep a server connection till the mail is received, only till your smtp server passed it successfully (or failed doing so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With