我正在尝试从 C# 桌面应用程序发送电子邮件,我在此页面上引用了此页面,这http://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=0
是我的代码,但它给了我以下异常
A socket operation was attempted to an unreachable network [2a00:1450:4008:c01::6c]:25
在这条线上
oSmtp.SendMail(oServer, oMail);
我哪里错了
private void sendmail()
{
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
oMail.From = "mo@gmail.com";
oMail.To = "mo@gmail.com";
oMail.Subject = "test email from c# project";
oMail.TextBody = "this is a test email sent from c# project, do not reply";
// Your SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// User and password for ESMTP authentication,
oServer.User = "mo@gmail.com";
oServer.Password = "account password here";
try
{
Console.WriteLine("start to send email ...");
oSmtp.SendMail(oServer, oMail);//getting error here
Console.WriteLine("email was sent successfully!");
}
catch (Exception ep)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ep.Message);
}