[英]Can't send mail via c# using monodevelop on linux mint
I have a function in a large c# project that receives an email and a confirmation code and needs to send an email to that address: 我在大型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;
}
}
This code, using windows sends the mail correctly and everything, but when I try using it on linux (mint) using monodeveloper it stucks and can't send anything.. It doesn't get an exception or anything, just get stucked. 使用Windows的这段代码可以正确发送邮件以及所有内容,但是当我尝试使用monodeveloper在linux(薄荷)上使用它时,它会卡住,无法发送任何内容。它不会出现异常或任何东西,只会卡住。 What to do?
该怎么办?
If things work on Windows and not in Mint it's not your code that's wrong. 如果一切在Windows上都能正常运行,而在Mint中却无法运行,那不是您的代码在哪里。 It's something within the Mint environment.
这是Mint环境中的东西。 Perhaps a firewall setting blocking outbound traffic on port 25??
也许是防火墙设置阻止了端口25上的出站流量? As an aside you could always try SendGrid to send the email.
顺便说一句,您可以始终尝试使用SendGrid发送电子邮件。 They have a number of libs that are easy to use.
它们具有许多易于使用的库。 I tend to use this API now whenever I need to send external emails.
现在,当我需要发送外部电子邮件时,我倾向于使用此API。
Regards Steve. 问候史蒂夫。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.