I have the following code to send email through SMTP:
Code:Private Sub SendMailToAdmin() Try RecipientAddress = "" Dim YesDate As String = Now.AddMonths(0).ToString("MMM yyyy") Dim oMsg As New MailMessage() oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SenderAddress) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SenderPassword) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", MailServer) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10) ' oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 587) oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", True) oMsg.From = DisplayID oMsg.To = strEmailErrorTo oMsg.Cc = strEmailErrorCc oMsg.Subject = "Testing Email " oMsg.BodyFormat = MailFormat.Html oMsg.Body = "<HTML><HEAD><style>.Bd1 { FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Verdana; TEXT-ALIGN: LEFT } " oMsg.Body &= "</style></HEAD><BODY class=Bd1>" oMsg.Body &= "Testing Email<br /><br />" oMsg.Body &= "</BODY></HTML>" SmtpMail.SmtpServer = MailServer SmtpMail.Send(oMsg) oMsg = Nothing Catch ex As Exception ErrorToAdmin("Billing: Failed To Send Out Testing Email " + ex.Message) End Try End Sub
I get the error when trying to send out email:
The transport failed to connect to the server.
Does anyone know the cause of it??




Reply With Quote