我需要能够通过Unity发送电子邮件(基本上用于登录),但是我什么都无法工作。我没有错误,超时参数不起作用(到达该参数后无任何反应),并且电子邮件未发送。它只是在等待smtp时“冻结”。SendMailAsync(mail); 我使用自定义的smtps(我公司的一个),这不是问题。
public static async void TestSendMail(string to)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mail");
mail.To.Add(new MailAddress(to));
mail.Subject = "test task";
mail.Body = "Body";
mail.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.UseDefaultCredentials = false;
smtp.Host = ("myhost");
smtp.Port = 465;
smtp.Credentials =
new System.Net.NetworkCredential("mail", "password");
smtp.EnableSsl = false; // not sure if it should be false, but tried both anyway
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Timeout = 1000; // it doesn't do anything
Debug.Log("Trying to send..."); // being printed
await smtp.SendMailAsync(mail); // freeze here
Debug.Log("Sent !"); // not being printed
}
}
catch (Exception e)
{
Debug.Log(e.ToString()); // no exception thrown
}
}
打印第一个调试日志,但不打印第二个,也不会抛出异常或任何异常。 我只是不明白...