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 / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

sending an email from windows application .net 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sridhar - 24 Oct 2007 23:45 GMT
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 = "to@mycompany.com"
           FromAddress = "from@mycompany.com"
           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
Ged - 25 Oct 2007 08:00 GMT
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.

Signature

Ged Moretta
www.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.

> Hi,
>
[quoted text clipped - 78 lines]
>
> Thanks
Sridhar - 25 Oct 2007 12:58 GMT
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,

> Hi Sridhar
>
[quoted text clipped - 96 lines]
> >
> > Thanks
Sridhar - 25 Oct 2007 17:51 GMT
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.

> Hi Ged,
>
[quoted text clipped - 117 lines]
> > >
> > > Thanks

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.