Sending email via SMTP

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.
 
J

Jared

Public Sub email_send(ByVal xFrom As String, ByVal xTo As String, ByVal
xSubject As String, ByVal xBody As String)

Dim MyMail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
Dim MySMTP As New System.Net.Mail.SmtpClient(webs.txSMTP.Text)

Try

MyMail = New System.Net.Mail.MailMessage(xFrom, xTo, xSubject, xBody)
MySMTP.Send(MyMail)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error!")
Trace.WriteLine(ex.ToString)
Trace.WriteLine(ex.Message.ToString)
Trace.WriteLine(ex.InnerException.ToString)
Trace.WriteLine(ex.Source.ToString)
End Try


End Sub
 
G

Guest

Here is the Trace:

A first chance exception of type 'System.Net.Mail.SmtpException' occurred in
System.dll
System.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 103
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)
System

I don't see anything there that helps me know why I can not connect to the
remote server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top