使用Gmail发送电子邮件

编程入门 行业动态 更新时间:2024-10-28 00:19:16
本文介绍了使用Gmail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用此代码从桌面应用程序发送电子邮件

Hi, I used this code to sending email from my desktop application

string smtpAddress = "smtp.gmail"; int portNumber = 587; bool enableSSL = true; string emailFrom = "xyz@gmail"; string password = "myPassword"; string emailTo = "xyz@yahoo"; string subject = "Hello"; string body = "Hello, I'm just writing this to say Hi!"; using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(emailFrom); mail.To.Add(emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; // Can set to false, if you are sending pure text. mail.Attachments.Add(new Attachment("C:\\n.txt")); using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } }

我有这个错误

and i have this error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

任何帮助?

any help ?

推荐答案

我测试了整个我自己的IDE中的代码和此问题的结果是用户名/密码匹配错误。 确保您使用的是服务器上有效用户名的正确密码。 可能的问题:你问的是关于Gmail的问题,但是你正在使用Yahoo smtp服务器。你确定你正在使用雅虎服务器凭据的正确设置,或者你错误地写了雅虎的主机地址吗? I have tested this entire code in my own IDE and the result for this problem was the username/password match error. Make sure that you're using the correct password for the valid username on the server. Possible issue: You're asking a question about Gmail, but you're using the Yahoo smtp server. Are you sure you're using the correct settings for credentials for the Yahoo server, or did you mistakenly wrote that Yahoo smpt host address?

首先 string smtpAddress =smtp.gmail; 秒 查看您的凭证,帐户的用户名和密码 first string smtpAddress = "smtp.gmail"; second check ur credentials , username and password of ur account

更多推荐

使用Gmail发送电子邮件

本文发布于:2023-10-07 10:23:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Gmail

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!