使用gmail SMTP从CSharp / .net发送邮件 [英] Sending Mail using gmail SMTP from CSharp/.net

查看:182
本文介绍了使用gmail SMTP从CSharp / .net发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  using(SmtpClient client = new SmtpClient(smtp.gmail.com,587))
{
//配置客户端
客户端.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(textBox1.Text,textBox3.Text);

client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage message = new MailMessage(
textBox1.Text,//从字段
textBox2.Text,//收件人字段
textBox4.Text,//电子邮件的主题
richTextBox1.Text //电子邮件正文
);

client.Send(message);

MessageBox.Show(Email has been sent。);
}

错误:SMTP服务器需要安全连接或该客户端未通过身份验证。服务器响应是:5.5.1需要身份验证



我一直在使用gmail得到这个错误,但能够使用其他SMTP服务器发送邮件。凭据是正确的。

解决方案

使用Gmail帐户看起来存在安全问题 p>

我也面临同样的问题,然后从这篇文章



该帖子提到您需要更改允许访问安全性较低的应用程序的帐户权限设置。



事实上,您在登录时会收到通知您的Gmail帐户。


using(SmtpClient client = new SmtpClient("smtp.gmail.com", 587)) 
{
    // Configure the client
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential(textBox1.Text, textBox3.Text);

    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    MailMessage message = new MailMessage(
    textBox1.Text, // From field
    textBox2.Text, // Recipient field
    textBox4.Text, // Subject of the email message
    richTextBox1.Text // Email message body
    );

    client.Send(message);

    MessageBox.Show("Email has been sent.");
}

Error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

I have been getting this error with gmail but am able to use other SMTP Servers to send mails. The credentials are correct.

解决方案

Looks like there is a security issue with Gmail account.

I have also faced that same issue and then found solution from this post.

The post mentioned that you need to change the Account Permission setting with "Access of Less secure App" Enabled.

In fact you will get notification when you logged in to your gmail account.

这篇关于使用gmail SMTP从CSharp / .net发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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