Hi,
I have some code:
This code was originally part of a web service, but for simplicitys sake it is called by a button click in a basic windows form application. On my machine I get this exception:
Apart from my machine only one other machine throw this exception. On all the machines tried this code runs perfectly ok with no exceptions and the email is received.
Can anyone explain what night be causing this to happen?
Thanks, Dave.
I have some code:
Code:
Imports System.Net.Mail
Public Function SendEmail(ByVal recipients As String, ByVal ccRecipients As String, ByVal subject As String, ByVal body As String, ByVal userName As String, ByVal userID As Int32) As Boolean
Dim from As String = System.Configuration.ConfigurationManager.AppSettings("ITHelpdeskEmailAddress")
Dim objMM As New MailMessage(from, recipients, subject, body)
If ccRecipients.Length > 0 Then
objMM.Cc.Add(ccRecipients)
End If
objMM.IsBodyHtml = True
objMM.Priority = MailPriority.High
Dim sender As New System.Net.Mail.SmtpClient("?")
sender.DeliveryMethod = SmtpDeliveryMethod.Network
sender.UseDefaultCredentials = True
sender.Send(objMM)
Return True
End Function
This code was originally part of a web service, but for simplicitys sake it is called by a button click in a basic windows form application. On my machine I get this exception:
ex.ToString "System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
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 NetMail.Form1.bSendEmail(String sRecipient, String sSubject, String sBody) in C:\Documents and Settings\djohnson\Desktop\NetMail\Form1.vb:line 67" String
Apart from my machine only one other machine throw this exception. On all the machines tried this code runs perfectly ok with no exceptions and the email is received.
Can anyone explain what night be causing this to happen?
Thanks, Dave.