本文介绍了使用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发送电子邮件
发布评论