我想使用Gmail帐户发送邮件 [英] I want to send mail using gmail account

查看:132
本文介绍了我想使用Gmail帐户发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

等待

client.Send(mail);

并给予例外



and give exception

System.Net.Mail.SmtpException: 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 at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at check_email.Email.Unnamed_Click(Object sender, EventArgs e) in c:\users\anwar ali\documents\visual studio 2015\Projects\check_email\check_email\Email.aspx.cs:line 





我是什么尝试过:





What I have tried:

string pweda = "password"; //(ConfigurationManager.AppSettings["password"]);
string from = "from@gmail.com"; //Replace this with your own correct Gmail Address
string to = "to@gmail.com"; 
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.To.Add(to);
            mail.From = new MailAddress(from);
            mail.Subject = "This is a test mail";
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = "Test Mail.";

            mail.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();

            //Add the Creddentials- use your own email id and password
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(from, pweda);
            client.Port = 587; // Gmail works on this port
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true; //Gmail works on Server Secured Layer

            try
            {
                client.Send(mail);
                Response.Write("Message Sent...");
            }
            catch (Exception ex)
            {
                Exception ex2 = ex;
                string errorMessage = string.Empty;
                while (ex2 != null)
                {
                    errorMessage += ex2.ToString();
                    ex2 = ex2.InnerException;
                }
                HttpContext.Current.Response.Write(errorMessage);
            }

推荐答案

您好,



查看此信息

使用Gmail发送电子邮件ASP.Net中的SMTP邮件服务器 [ ^ ]


登录gmail,使用此网址打开新标签通过应用程序支持Gmail。 [ ^ ] - >单击 - 打开

现在运行您的代码,它应该工作。



当我来到这个问题时,我只记得这篇文章并回答了它。
login to gmail, open new tab with this url Gmail support via Apps.[^] -> Click - Turn On
Now run your code, it should work.

when i came accorss this issue, i just remembered this post and answered to it.


这篇关于我想使用Gmail帐户发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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