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:
The error message is that it can not connect to the smtp server. Again, the smtp server is a remote server.here is a trace of the error:
I don't see anything there that helps me know why I can not connect to the remote server.--
Thanks,enak
VB.NET:
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("from@address.com"), New MailAddress([EMAIL="to@address.com"]to@address.com[/EMAIL]))
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.here is a trace of the error:
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dllSystem.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at WindowsApplication1.Email.SendEmailMessage() in D:\Email.vb:line 103Failure sending mail.System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)System
I don't see anything there that helps me know why I can not connect to the remote server.--
Thanks,enak