While sending the email using async getting error.
- Public Async Function SendEmail(ByVal EmailToIds As String, ByVal Subject As String, ByVal Message As String, Optional ByVal EmailCcIds As String = "", Optional ByVal MailAttachment As String = "", Optional ByVal FromEmailType As Integer = 0, Optional EmailBccIds As String = "") As Task
- Dim EmailPwd() As String
- Dim FromEmail, Password As String
-
- Dim objMail As MailMessage
- Dim objAttachment As Attachment
- Try
- EmailPwd = GetEmailPassword(FromEmailType).Split("|")
- FromEmail = EmailPwd(0)
- Password = EmailPwd(1)
- objMail = New MailMessage
- objMail.From = New MailAddress(FromEmail)
- objMail.Subject = Subject
- objMail.IsBodyHtml = True
- objMail.Body = Message
- objMail.To.Add(EmailToIds)
- If Len(EmailCcIds) > 0 Then
- objMail.CC.Add(EmailCcIds)
- End If
- If Len(EmailBccIds) > 0 Then
- objMail.Bcc.Add(EmailBccIds)
- End If
- If MailAttachment <> "" Then
- objAttachment = New Attachment(MailAttachment)
- objMail.Attachments.Add(objAttachment)
- End If
- Using objSmtp = New SmtpClient()
- objSmtp.Host = ConfigurationSettings.AppSettings("SmtpClient")
- objSmtp.DeliveryMethod = SmtpDeliveryMethod.Network
- objSmtp.UseDefaultCredentials = False
- objSmtp.Credentials = New NetworkCredential(FromEmail, Password)
- objSmtp.Port = 587
- objSmtp.EnableSsl = True
- ServicePointManager.ServerCertificateValidationCallback = Function(s As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) True
- Await objSmtp.SendMailAsync(objMail)
- End Using
- Catch ex As Exception
- throw rx
- End Try
- End Function
Error : Failure Sending Mail.
Kindly help for the same.