SMTP服务器需要安全连接或客户端未经过身份验证。发送邮件的例外情况

时间:2014-04-23 05:03:05

标签: c# email authentication

我正在尝试通过c#代码发送邮件,但我收到以下异常。 The SMTP server requires a secure connection or the client was not authenticated。服务器响应是:5.5.1 Authentication Required.This代码工作正常,如果我使用我的个人gmail smtp设置发送邮件但是当我使用客户端smptp设置它给我这个例外。应用程序托管在美国服务器上

我不知道我在哪里做错了plz帮助。

 public static void sendBulkMail()
 {   
            DataSet _ds = new DataSet();
            SMTPBAL smtpbl = new SMTPBAL(0);
            smtpbl.LoadAll(_ds);    
            string server = _ds.Tables[smtpbl.SqlEntityX].Rows[0]["SMTPX"].ToString();
            int smtpPort = WebHelper.Cast(_ds.Tables[smtpbl.SqlEntityX].Rows[0]["smtpPort"].ToString(), 0);
            string From = _ds.Tables[smtpbl.SqlEntityX].Rows[0]["Email"].ToString();
            string User = _ds.Tables[smtpbl.SqlEntityX].Rows[0]["User"].ToString();
            string Password = _ds.Tables[smtpbl.SqlEntityX].Rows[0]["Password"].ToString();
            string sDisclaimer = _ds.Tables[smtpbl.SqlEntityX].Rows[0]["Disclaimer"].ToString();
            bool EnableSSl = WebHelper.Cast(_ds.Tables[smtpbl.SqlEntityX].Rows[0]["EnableSll"], false);
            string EmailAddress = string.Empty;

            StudentBAL _stbl = new StudentBAL(0);
            _stbl.LoadAll(_ds);

            foreach (DataRow dr in _ds.Tables[_stbl.SqlEntityX].Rows)
            {
                try
                {
                    if (dr["Email"] != DBNull.Value)
                    {
                        if (IsValidMailAddress(dr["Email"].ToString()))
                        {
                            string Message = "Dear parent,<br/><br/> <br/> The Attendance for current course/semester of your ward," + dr["Name"].ToString() + " is available on the given below link.Please check and contact HOD in case any enquiry.<br/><br/><br/>Copy below link to your browsers address bar. <br/><br/>http://insr.MNMtechnologies.net/login/login.aspx <br/>User Name :" + dr["LoginEmailAddress"].ToString() + " / " + dr["EmailAddress"].ToString() + "<br/>Password : " + dr["Password"].ToString() + "<br/><br/><br/>Regard's<br/><br/>Institute of   management.<br/> .";
                            SMTPHelper SMTP1 = new SMTPHelper(server, smtpPort, From, Password, EnableSSl, true);
                            SMTP1.IsHTML = true;
                            SMTP1.SendEmail(From, "Institute of management", dr["Email"].ToString(), "", "", "Attendance status of your ward.", Message, false);
                        }
                    }
               }
               catch (Exception err) { }   
          }
  }

1 个答案:

答案 0 :(得分:0)

前段时间我遇到过类似问题,建议您重新检查以下内容:

  • EnableSSL true或false
  • 再次检查凭据
  • 有时某些SMTP服务器(主要用于公司)不允许外部访问或具有单独的IP用于外部访问
  • 检查用户名是否应包含@ Host.com或没有

我希望其中一个适合你。