<add key="MailServer" value="smtp.live.com  "/>
<add key="MailServerUser" value="[email protected]"/>
<add key="MailServerPassword" value=""/>出错信息:
SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.0 Must issue a STARTTLS command first 

解决方案 »

  1.   

    参考下面代码。
    你的代码是一些变量和值而已,和string MailServer="smtp.live.com" 没区别,无非是写的地方不同而已。端口号不用写,只要邮件服务器的对应端口对WEB服务器开放就行了。private void PostMail(string mTo, string mSubject, string mBody)
            {
                SmtpClient smtpClient = new SmtpClient();
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//.Network;//指定电子邮件发送方式
                smtpClient.Host = SMTP; //指定SMTP服务器
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new System.Net.NetworkCredential(UserName, Password);//用户名和密码            String body = mBody;
                MailMessage mailMessage = new MailMessage(MailAddress, mTo);            mailMessage.Subject = mSubject;//主题
                mailMessage.Body = body;//内容
                mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
                mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;            mailMessage.IsBodyHtml = true;//设置为HTML格式
                mailMessage.Priority = MailPriority.Normal;//优先级            try
                {
                    smtpClient.Send(mailMessage);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }        }