mail sending with network credential as true in windows form not working

别说谁变了你拦得住时间么 提交于 2019-11-26 15:33:18

gmail uses port 587

oClient.Port = 587;

You may also want to set UseDefaultCredentials to false and explicitly declare username and password. By declaring it to be true, you are trying to log into your gmail account using your windows credentials.

oClient.UseDefaultCredentials = false;
oClient.Credentials = new NetworkCredential("email@gmail.com", "password");

Also, in gmail security, you will need to allow Less Secure Applications.

Finally, you need to change how your Mail.To is populated:

oMail.To.Add(new MailAddress(txtTo.Text.Trim()));

Google may block sign in attempts from some apps or devices when you try to login from some app. You need to go to security settings at your gmail and enable less secure apps . So that you will be able to login from all apps. Go to Allow less secure apps and choose Allow to let less secure apps access your Google account. Have a look at this link may useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!