SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证. .. im gettin client.send(message)中的此异常; [英] The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. .. im gettin this exception in client.send(message);

查看:126
本文介绍了SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证. .. im gettin client.send(message)中的此异常;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Net.Mail;
using System.Web;
//using System.Web.Mail;
using System.Web.Security;
using System.Net.Mail;
using System.Configuration;using System.Net.Mail;
using System.Configuration;

namespace MvcApplication3.Managers
{
    public class EmailManager
    {
        private const string EmailFrom = "user@gmail.com";
        public static void SendConfirmationEmail(string userName)
        {
            var user = Membership.GetUser(userName.ToString());
            var confirmationGuid = user.ProviderUserKey.ToString();
            var verifyUrl = HttpContext.Current.Request.Url.GetLeftPart
               (UriPartial.Authority) + "/Account/Verify/" + confirmationGuid;

            using (SmtpClient client = new SmtpClient())
            {
                using (var message = new MailMessage(EmailFrom, user.Email))
                {
                    message.Subject = "Please Verify your Account";
                    message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + user.UserName +
                        ", </p><p>To verify your account, please click the following link:</p>"
                        + "<p><a href=\"" + verifyUrl + "\" target=\"_blank\">" + verifyUrl
                        + "</a></p><div>Best regards,</div><div>Someone</div><p>Do not forward "
                        + "this email. The verify link is private.</p></body></html>";

                    message.IsBodyHtml = true;
                    client.Port = 587;
                    
                    client.EnableSsl = true;


                   // client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Send(message);
                };
            };
        }
    }
}

推荐答案

启用S​​SL时的端口号....
将其更改为此[用于发送SSL邮件]:-

There is a problem with the Port No when SSL is enabled....
Change it to this [For sending SSL mails] :-

using System;
using System.Net.Mail;
using System.Web;
//using System.Web.Mail;
using System.Web.Security;
using System.Net.Mail;
using System.Configuration;using System.Net.Mail;
using System.Configuration;
 
namespace MvcApplication3.Managers
{
    public class EmailManager
    {
        private const string EmailFrom = "user@gmail.com";
        public static void SendConfirmationEmail(string userName)
        {
            var user = Membership.GetUser(userName.ToString());
            var confirmationGuid = user.ProviderUserKey.ToString();
            var verifyUrl = HttpContext.Current.Request.Url.GetLeftPart
               (UriPartial.Authority) + "/Account/Verify/" + confirmationGuid;
 
            using (SmtpClient client = new SmtpClient())
            {
                using (var message = new MailMessage(EmailFrom, user.Email))
                {
                    message.Subject = "Please Verify your Account";
                    message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + user.UserName +
                        ", </p><p>To verify your account, please click the following link:</p>"
                        + "<p><a href="\""" verifyurl="" target="\"_blank\"">" + verifyUrl
                        + "</a></p><div>Best regards,</div><div>Someone</div><p>Do not forward "
                        + "this email. The verify link is private.</p></body></html>";
 
                    message.IsBodyHtml = true;
                    client.Port = 465;
                    
                    client.EnableSsl = true;
 

                   // client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Send(message);
                };
            };
        }
    }
}



将其更改为[用于发送TLS/STARTTLS/非SSL邮件]:-



Change it to this [For sending TLS/ STARTTLS/ non SSL mails] :-

using System;
using System.Net.Mail;
using System.Web;
//using System.Web.Mail;
using System.Web.Security;
using System.Net.Mail;
using System.Configuration;using System.Net.Mail;
using System.Configuration;
 
namespace MvcApplication3.Managers
{
    public class EmailManager
    {
        private const string EmailFrom = "user@gmail.com";
        public static void SendConfirmationEmail(string userName)
        {
            var user = Membership.GetUser(userName.ToString());
            var confirmationGuid = user.ProviderUserKey.ToString();
            var verifyUrl = HttpContext.Current.Request.Url.GetLeftPart
               (UriPartial.Authority) + "/Account/Verify/" + confirmationGuid;
 
            using (SmtpClient client = new SmtpClient())
            {
                using (var message = new MailMessage(EmailFrom, user.Email))
                {
                    message.Subject = "Please Verify your Account";
                    message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + user.UserName +
                        ", </p><p>To verify your account, please click the following link:</p>"
                        + "<p><a href="\""" verifyurl="" target="\"_blank\"">" + verifyUrl
                        + "</a></p><div>Best regards,</div><div>Someone</div><p>Do not forward "
                        + "this email. The verify link is private.</p></body></html>";
 
                    message.IsBodyHtml = true;
                    client.Port = 587;
                    
                    client.EnableSsl = false;
 

                   // client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Send(message);
                };
            };
        }
    }
}


这篇关于SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证. .. im gettin client.send(message)中的此异常;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆