我試圖理解爲什麼我不能夠發送郵件異步(也許這是關係我是從NUnit的運行呢?發送使用SendMailAsync電子郵件從NUnit的
當我做一些簡單的smtp.Send(mail);
是運作良好
// Nunit test
{
[TestFixture]
public class Tester
{
[Test]
public void TestSendTestMail()
{
// Arrange
// Act
await EbayProxy.Instance.SendTestMail();
// Assert
}
}
public async Task SendTestMail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(_mailFrom);
mail.To.Add(_mailTo);
mail.Subject = "Test Mail Subject Async";
mail.Body = "Test Mail Body";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(_smtpClient, Convert.ToInt32(_smtpPort));
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential(_mailFrom, _mailFromPassword);
await smtp.SendMailAsync(mail); // Not sending mail :(
}
開始閱讀... http://blog.stephencleary.com/2012/02/async-and-await.html – Mick