发送消息失败 [英] Failure sending message

查看:81
本文介绍了发送消息失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前遇到了我的程序问题它不断给我同样的错误无论我多少次更改我的代码,代码是相同的格式所以我不知道什么问题甚至改变了端口到587到25



I'm currently having problems with my program it keeps giving me the same error no matter how many times I change my code, the code is in the same format so I dont know what the problem even changed the port to 587 to 25

MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("xhasiwe@gmail.com");
                mail.To.Add("bella.moqekwa@expeditors.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("xhasiwe", "mypassword");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                Console.WriteLine("mail Send");

< br $>




错误是内部异常(无法连接到远程服务器)




The Error is that inner exception (Unable to connect to the remote server)

推荐答案







Hi,


string UserName="gmail's user Name";
string Password="gmail's Password";

MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
 
                mail.From = new MailAddress("xhasiwe@gmail.com");
                mail.To.Add("bella.moqekwa@expeditors.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";
 
                SmtpServer.Port = 465;
                SmtpServer.Credentials = new System.Net.NetworkCredential(UserName, Password);
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);
                Console.WriteLine("mail Send")





试试这个......



Try this...


这篇关于发送消息失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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