不能在linux mint上使用monodevelop通过c#发送邮件
本文关键字:通过 monodevelop linux mint 不能 | 更新日期: 2023-09-27 18:08:58
我在一个大型c#项目中有一个函数,它接收电子邮件和确认码,并需要向该地址发送电子邮件:
public int sendVerificationEmail (string email, int randomNumber)
{
try
{
SmtpClient client = new SmtpClient ();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential ("wsep142@gmail.com", "<PASSWORD>");
MailMessage mm = new MailMessage ("wsep142@gmail.com", email, "Registration to the forum system", "This is your authentication code: " + randomNumber.ToString () + ".'n Please enter this link: www.myawesomewebsite.com and insert the code. 'n Thank you and have a great day. 'n WSEP142 Forum team.");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send (mm);
return 0;
}
catch(Exception)
{
return -1;
}
}
这个代码,使用windows发送正确的邮件和一切,但是当我尝试在linux (mint)上使用monodeveloper使用它时,它卡住了,不能发送任何东西。它不会得到异常或任何东西,只是被卡住了。该怎么办?
如果事情在Windows上工作,而不是在Mint上,这不是你的代码有问题。这是Mint环境中的一些东西。也许防火墙设置阻止在端口25出站流量??顺便说一句,您总是可以尝试SendGrid来发送电子邮件。它们有许多易于使用的库。当我需要发送外部邮件时,我倾向于使用这个API。
的问候史蒂夫。