sending an email from windows application .net 2.0

G

Guest

Hi,

I have created a windows application to send emails using vs 2005 in
vb.net. I am having problems sending the emails. The operating system on
which this application is run is windows vista business. we have an exchange
server 2007 that is in the same network. I am trying to send the emails using
the exchange server with the following code.

Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSendEmail.Click
Dim errMsg As String
Dim ToAddress As String
Dim FromAddress As String
'Dim mailman As New Chilkat.MailMan
Try
ToAddress = "(e-mail address removed)"
FromAddress = "(e-mail address removed)"
Dim mm As New MailMessage(FromAddress, ToAddress)

mm.Subject = "Test"
mm.Body = "Test Email"
mm.IsBodyHtml = False

Dim smtp As New SmtpClient
smtp.Host = "exchangeserver ip address"
smtp.Port = 25
'smtp.se()
smtp.Credentials = New
System.Net.NetworkCredential("exchangeserveripaddress\myusername",
"mypassword")
smtp.UseDefaultCredentials = False
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
Try
smtp.Send(mm)
Catch ex As Exception
errMsg = ex.ToString()
End Try

Catch ex As Exception

End Try

Following is the error that I am receiving when I run the code.

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 WindowsApplication1.Form1.btnSendEmail_Click(Object sender, EventArgs
e) in C:\Users\sduggireddy\Documents\Visual Studio
2005\Projects\WindowsApplication1\WindowsApplication1\Form1.vb:line 162

I am not knowing how to debug this. Please let me know.

Thanks
 
G

Guest

Hi Sridhar

Looking at the error stack, the line

"System.Net.Sockets.SocketException: No connection could be made because the
target machine actively refused it"

sticks out for me.

So, a couple of questions.

1. Does the exchange server allow you to send using SMTP ?
2. Is Exchange listening on port 25 ?
3. Are your credentials correct?

I would get a standard mail client (i.e. Windows Mail, Thunderbird etc) and
see if it can send email via exchange server using SMTP.
 
G

Guest

Hi Ged,

Thanks for the reply. I am sure that our exchange server will allow to
send emails through smtp. We have a .net 1.1 windows application which uses
chilkat.net dll to send the emails. when i looked at the code, I saw that we
are setting a property smtphost. so I think our exchange server 2007 will
send emails via smtp.

Regarding the exchange server using port 25 I tested this using telnet. when
I do telnet exchangeipaddress 25 it is connected. but I did this test on
another machine. when I do the same test on my computer it says "could not
opeb connection to the host on port 25"

Like I said before I am using windows vista business edition. I am thinking
that the firewall is blocking it or something like that. I am not knowing how
to unblock.

Please let me know.

Thanks,
 
G

Guest

I have finally figured it out. It is the virus scanner that is blocking the
connection. So I unchecked it and it worked fine.

Thanks,
sridhar.
 

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

Top