首页 > 解决方案 > SMTP 服务器需要安全连接。- 控制台应用程序

问题描述

当我打开我的控制台应用程序项目时,它说:

在此处输入图像描述

这是我的代码:

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your mail@gmail.com");
mail.To.Add("to_mail@gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:\text.txt");
mail.Attachments.Add(attachment);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("save111sender@gmail.com", "test123test.");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);

请帮我解决这个问题。

标签: c#consoleconsole-application

解决方案


推荐阅读