带有ASP.net错误5.5.1的SMTP邮件需要身份验证 [英] SMTP Mail with ASP.net Error 5.5.1 Authentication Required

查看:96
本文介绍了带有ASP.net错误5.5.1的SMTP邮件需要身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我是使用ASP.net和SMTP Mailer的初学者

Good day, I'm a beginner from using ASP.net and SMTP Mailer

这里是我的问题,当我从本地发送电子邮件时,总是会遇到此错误并在网上搜索并尝试了解决方案,但并没有那么幸运,我希望有人指出我需要什么代码以及我在哪里遇到此错误

Heres my Question, I always encounter this Error when i send email from my local and searched and tried the solutions around the net but not so lucky, I hope someone point out what codes do i need and where i encounter this errror

Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

在这里输入我的代码:

protected void btnSendEmail_Click(object sender, EventArgs e)
        {
            // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
            // System.Net.Mail.SmtpClient is the alternate class for this in 2.0
            SmtpClient smtpClient = new SmtpClient();
            MailMessage message = new MailMessage();

            try
            {
                MailAddress fromAddress = new MailAddress(txtEmail.Value, txtName.Value);
                smtpClient.Credentials = new System.Net.NetworkCredential("myUser@gmail", "password");
                // You can specify the host name or ipaddress of your server
                // Default in IIS will be localhost 
                smtpClient.Host = "smtp.gmail.com";
                smtpClient.EnableSsl = true;
                //Default port will be 25
                smtpClient.Port = 25;
                smtpClient.UseDefaultCredentials = false;
                //From address will be given as a MailAddress Object
                message.From = fromAddress;

                // To address collection of MailAddress
                message.To.Add("myEmail@gmail.com");
                message.Subject = txtSubject.Value;

                // CC and BCC optional
                // MailAddressCollection class is used to send the email to various users
                // You can specify Address as new MailAddress("admin1@yoursite.com")
                message.CC.Add("myEmail@gmail.com");

                // You can specify Address directly as string
                message.Bcc.Add(new MailAddress("myEmail@gmail.com"));

                //Body can be Html or text format
                //Specify true if it  is html message
                message.IsBodyHtml = false;

                // Message body content
                message.Body = txtaMessage.Value;
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.HeadersEncoding = System.Text.Encoding.UTF8;
                // Send SMTP mail
                smtpClient.Send(message);

                lblSuccess.Text = "Email successfully sent.";
            }
            catch (Exception ex)
            {
                lblSuccess.Text = "Send Email Failed.";
            }
        }

推荐答案

尝试使用此参考资料

Try this reference ASP Simple SMTP for C# and VB it helps me a lot for may smtp problem

这篇关于带有ASP.net错误5.5.1的SMTP邮件需要身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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