使用gmail进行Smtp C#身份验证 [英] Smtp C# authentification using gmail

查看:134
本文介绍了使用gmail进行Smtp C#身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

here is my code:

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.To.Add("test@gmail.com");
                    message.Subject = "Nici un Clinet valabil pentru reparare";
                    message.From = new System.Net.Mail.MailAddress("test@gmail.com");
                    message.Body = "Nu mai sunt clienti la care mecanicii sa lucreze";
                    string sendEmailsFrom = "test@gmail.com";
                    string sendEmailsFromPassword = "my_invisible_password";
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword);
                    smtp.Timeout = 20000;
                    smtp.Send(message);





我的错误:

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



有什么问题?我无法看到它,也无法在谷歌上找到解决方案。



谢谢,

Sas Gabriel



我的尝试:



电子邮件



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

What is the problem? i can't see it and can't find a solution on google.

Thanks,
Sas Gabriel

What I have tried:

email

推荐答案

你需要设置

You need to set
UseDefaultCredentials = false;

首先和之后设置你想要使用的凭证



first and after that set the credentials you want to use

Credentials = new NetworkCredential("gabitza.sas@gmail.com", "my_invisible_password");





另外确保您可以使用mail.google.com页面上的用户名和密码登录。



祝你好运,

OI



Also make sure you can login from with your username and password from the mail.google.com page.

Good luck,
OI


另请注意,当您进行大量连接时,谷歌会阻止您登录n次尝试。



我总是使用本地电子邮件服务器进行开发: http:// www.hmailserver.com/ [ ^ ]

它是免费的。您只需配置它并在您的计算机上运行它,连接到localhost:2525。

请务必关闭此禁令选项(自动禁止)。
Also please be aware that google will block you from logging in when you do to much connection attempts.

I always use a local email server for development: http://www.hmailserver.com/[^]
It's free. You can simply configure it and run it on your computer, connecting to localhost:2525.
Please be sure to also turn down the ban-option ("auto-ban") of this one.


Goto Account of Gmail , then select Connected apps & sites Allow less secure apps: ON(if this is off you cannot send mails through apps,or your websites )


这篇关于使用gmail进行Smtp C#身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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