Hi,
I am busy with an application that needs to send an email through my company's exchange server. But when my application tries to send the email I get the following error:
The following exception occurred: 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
Here is the code that I am using:
using
System;using
System.Collections.Generic;using
System.Text;using
System.Net.Mail;using
System.Net;using
PMonThread.Properties;namespace
PMonThread{
class EMail{
public void SendEMail(string body, string subject){
// initializes the mailmessage object and adds the appropriate valuesMailMessage mail =
new MailMessage();mail.From =
new MailAddress("");mail.To.Add(
"");mail.Subject = subject;
mail.Body = body;
SmtpClient smtp =
new SmtpClient(""); try{
smtp.Send(mail);
}
catch (Exception ex){
throw ex;}
}
}
Sateesh ArvetiPosted Mar 5, 2009, 2:28 AM
NetworkCredential myCreds = new NetworkCredential("UserName", "Password", "");
smtp.Credentials = myCreds;
or
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
If you are getting still problem,check whether any firewall or anti virus is blocking it.
Waldo JewellPosted Mar 5, 2009, 4:15 PM
Hi,
Just checked the logs of my antivirus, and it is blocking my application from sending the email.
Is there anyway to bypass it with out disabling the antivirus?
Waldo JewellPosted Mar 5, 2009, 4:10 PM
Hi,
I have tried using credentials, it still gave the same error. I also tried using port 80 but it gave me an timed out error
You mentioned the antivirus firewall, do you mean on my pc or on the server?
Your help is much appreciated
Thanks,
Waldo