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 values
MailMessage 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;
}
}
}