I'm receiving the following error when trying to send an email using System.Net.Mail. I'm using a remote SMTP server which is a Windows 2003 server. I've added the machine which is sending the mail in the relay settings. Port 25 is open in the firewall settings.
Here is the Error I receive:
ion: Failure sending mail. --->
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketE
xception: No connection could be made because the target machine actively refused it 220.127.116.11:25 at System.Net.Sockets.Socket.
EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.
oint remoteEP) at System.Net.ServicePoint.Co
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.Ge
ream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Ac
ect owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Ac
ect owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.
owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnec
tring host, Int32 port) at System.Net.Mail.SmtpTransp
ring host, Int32 port) at System.Net.Mail.SmtpClient
tion() at System.Net.Mail.SmtpClient
Message message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient
Message message) at _Default.Button1_Click(Obj
ect sender, EventArgs e) in e:\Code\VPAF\DW\TestEmail2
Any suggestions on why the email is not being sent?
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("fromemail");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body";
//send the message
SmtpClient smtp = new SmtpClient();
smtp.Host = "ipaddress";
smtp.Port = 25;
catch (Exception ex)
string strError = ex.ToString();
lblError.Text = strError;