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

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

问题描述

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.");
}

错误:SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应为:5.5.1 Authentication Required.

我在使用 gmail 时遇到了这个错误,但我可以使用其他 SMTP 服务器来发送邮件.凭据正确.

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

推荐答案

Gmail 帐户似乎存在安全问题.

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.

事实上,当您登录到您的 gmail 帐户时,您会收到通知.

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

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

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