G
Guest
I need to be able to send email via a remote SMTP server. I am having trouble
connecting to the server.
Here is my code:
Public Sub SendEmailMessage()
Dim dr As SqlClient.SqlDataReader
Dim smtpCredentials As New Net.NetworkCredential("myusername",
"password")
'For each to address create a mail message
Dim MailMsg As New MailMessage(New
MailAddress("(e-mail address removed)"), New MailAddress("(e-mail address removed)"))
MailMsg.Subject = "Test JWI"
MailMsg.Body = "Testing" & vbCrLf
MailMsg.Priority = MailPriority.Normal
MailMsg.IsBodyHtml = True
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.UseDefaultCredentials = False
SmtpMail.Host = "smtp.remotesite.com"
SmtpMail.Credentials = smtpCredentials
SmtpMail.Send(MailMsg)
End If
cnn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
The error message is that it can not connect to the smtp server. Again, the
smtp server is a remote server.
connecting to the server.
Here is my code:
Public Sub SendEmailMessage()
Dim dr As SqlClient.SqlDataReader
Dim smtpCredentials As New Net.NetworkCredential("myusername",
"password")
'For each to address create a mail message
Dim MailMsg As New MailMessage(New
MailAddress("(e-mail address removed)"), New MailAddress("(e-mail address removed)"))
MailMsg.Subject = "Test JWI"
MailMsg.Body = "Testing" & vbCrLf
MailMsg.Priority = MailPriority.Normal
MailMsg.IsBodyHtml = True
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.UseDefaultCredentials = False
SmtpMail.Host = "smtp.remotesite.com"
SmtpMail.Credentials = smtpCredentials
SmtpMail.Send(MailMsg)
End If
cnn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
The error message is that it can not connect to the smtp server. Again, the
smtp server is a remote server.