尽管所有端口都处于打开和活动状态,但无法发送电子邮件

时间:2014-12-01 10:59:06

标签: c# asp.net email smtp

我的代码会将电子邮件发送到用户在注册时提供的电子邮件ID。它可以是我们公司的域名id,也可以是任何其他域名。

现在有3个不同的按钮可以调用三个不同的电子邮件页面。请假可以被批准,拒绝或取消。代码是通用的,只有男孩改变,结果通过改变状态字段的值反映在数据库上。

以下是我正在使用的代码:

    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>

根据我使用的端口号,我得到3个不同的错误。 由于我使用上面的端口587,我收到以下错误:

    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)

当我将端口号更改为465时,错误为:

   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);

当我使用端口25时,错误再次出现:

    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)

我试图在指定端口上打开与邮件服务器的telnet连接。它有效。 我甚至通过防火墙检查了允许程序中的HTTP服务选项。

我还检查了防火墙是否阻止了什么,但它没有。我手动启用防火墙以允许所有与电子邮件相关的端口。我与管理员核实了任何阻止权限,但没有任何限制,不允许我发送电子邮件。 作为最后的手段,我在我的计算机上安装了我公司的邮件客户端,并尝试在各种端口上使用smtp。

一切正常。除了在这个网站上。 请帮忙。

1 个答案:

答案 0 :(得分:0)

在这里检查问题的答案 - 看起来很相似: Getting "The remote certificate is invalid according to the validation procedure" when SMPT server has a valid certificate

  

我最终发现的答案是服务器上的SMTP服务没有使用与https相同的证书。

     

我在这里阅读的诊断步骤假设他们使用了   相同的证书,每次我过去都尝试过这个证书   完成和诊断步骤正是我为解决这个问题所做的   问题好几次。

     

在这种情况下,由于使用的证书,这些步骤不起作用   是不同的,这是我从来没有的可能性   碰到了。

     

解决方案是从中导出实际证书   服务器,然后将其作为可信证书安装在我的计算机上,或   获取SMTP服务的不同有效/可信证书   服务器。目前我们的IT部门负责管理   服务器决定他们想做什么。