I am having an issue using the SendMailAsync
When I change it out for a normal Send
it works fine. When I use SendMailAsync
I get a connection has timed out and no mail is sent. Am I setting it up the wrong way?
edit:
1. I changed the variable name!!!
2.The exact error happens here await smtpClient.SendMailAsync(mailMessage);
It just hangs until the connection times out, and I get an error description of "Connection has timed out" The status code returned is General Error
I'm calling the sendEmail from form the onClick event of a button for now.
await unitOfWork.Instance.SendEmail(...)
It's a single line of code in the onclick eventpublic async Task SendEmail(List<string> notificationList, string emailSubject, string emailMessage) { var message = new MailMessage() { IsBodyHtml = true, BodyEncoding = System.Text.Encoding.UTF8, Subject = emailSubject, From = new MailAddress(FromEmailAddress), Body = emailMessage }; try { foreach (var emailAddress in notificationList) { message.To.Add(emailAddress); } var people = string.Join(Environment.NewLine, message.To); MessageBox.Show(@"from: " + unitOfWork.CurrentSystemUser.Person.Email + "To: " + people); await SendMessage(message); } catch (Exception E) { ... } finally { ... } } private async Task SendMessage(MailMessage mailMessage) { if (!CanSendSmtpEmail) return; await SendSmtpMail(mailMessage); } public async Task SendSmtpMail(MailMessage mailMessage) { SmtpClient smtpClient = new SmtpClient(SmtpClientHost, int.Parse(SmtpClientPort)); smtpClient.SendCompleted += (s, e) => { smtpClient.Dispose(); mailMessage.Dispose(); }; await smtpClient.SendMailAsync(mailMessage); //smtpClient.Send(mailMessage) works fine }