Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Sending email via SMTP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
enak - 23 Aug 2006 20:17 GMT
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("from@address.com"), New MailAddress("to@address.com"))
               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.

Signature

enak

Jared - 23 Aug 2006 23:53 GMT
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
enak - 29 Aug 2006 15:19 GMT
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.

Signature

enak

> Public Sub email_send(ByVal xFrom As String, ByVal xTo As String, ByVal
> xSubject As String, ByVal xBody As String)
[quoted text clipped - 15 lines]
>
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.