I have code which sends email to the email id that has been fed by the user on registration. It can be either our company domain id or any other domain for that matter.
Now there are 3 different buttons which call three different email pages. Leave can be approved, denied or cancelled. The code is generic, only the boy changes and the result is reflected on the database by changing values of status field.
Here is the code I am using:
try
{
string fromEmail = ConfigurationManager.AppSettings["EmailID"].ToString();
string toEmail = lbl_emp_email.Text.Trim();
string bcc = Convert.ToString(lbl_logger_mailID.Text);
MailMessage message = new MailMessage(fromEmail, toEmail);
message.CC.Add("abcd@aaaa-india.org");
message.Bcc.Add(new MailAddress(bcc));
//send email to sender,the boss in this case.notify him he has approved a leave request
message.Subject = lbl_subject.Text.Trim();
message.Body = txt_mail_body.Text.Trim();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.aaaa-india.org";
smtp.Send(message);
Response.Write("<script type=\"text/javascript\">alert('Notification of leave approval sent.');</script>");
}
catch (Exception exce)
{
Response.Write("MAIL NOT SENT. AN ERROR OCCURRED." + exce.ToString());
}
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="support@aaaa-india.org" >
<network defaultCredentials="false"
enableSsl="true"
host="smtp.aaaa-india.org"
port="587"
userName="support@aaaa-india.org"
password="abcd"/>
</smtp>
</mailSettings>
</system.net>
<appSettings>
<add key="EmailID" value="support@aaaa-india.org"/></appSettings>
I get 3 different errors depending on the port number i use. As I have used the port 587 above I get the following error:
MAIL NOT SENT. AN ERROR OCCURRED.
System.Security.Authentication.AuthenticationException:
The remote certificate is invalid according to the validation procedure. at
System.Net.Security.SslState.StartSendAuthResetSignal
(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)at
System.Net.Security.SslState.CheckCompletionBeforeNextReceive
(ProtocolToken message, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartSendBlob
(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ProcessReceivedBlob
(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartReadFrame
(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartReceiveBlob
(Byte[] buffer, AsyncProtocolRequest asyncRequest)
When i change the port number to 465 the error is:
AN ERROR OCCURRED. System.Net.Mail.SmtpException: The operation has timed out. at
System.Net.Mail.SmtpClient.Send(MailMessage message)
at the line smtp.Send(message);
When i use the port 25 the error is again:
MAIL NOT SENT. AN ERROR OCCURRED.
System.Security.Authentication.AuthenticationException:
The remote certificate is invalid according to the validation procedure. at
System.Net.Security.SslState.StartSendAuthResetSignal
(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) at
System.Net.Security.SslState.CheckCompletionBeforeNextReceive
(ProtocolToken message, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartSendBlob
(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
I have tried to open a telnet connection to the mail server on the specified port. And it works. I even checked HTTP services option in Allow a program through the firewall.
I also checked into the firewall if it is blocking anything, but its not.I manually enabled the firewall to allow all the email related ports. I checked with my administrator for any blocking privileges, but there are no restrictions that wont let me send email. As a last resort i installed my company's mail client on my computer and tried using smtp on various ports.
Everything works. Except in this website. Please help.