2017-07-18 118 views
1

下面的C#代码VS2017显示邮件已成功发送。我可以从我的outlook帐户的发件箱中验证电子邮件确实已成功发送。但是在我的Yahoo帐户中,即使超过一个小时,电子邮件也不存在。 问题:东西在这里我的代码缺少 - 我们怎样才能使它发挥作用? 注意:我已经在我的Outlook的发件箱,无论FromTo邮件地址是正确的验证。我正在关注这个Technet articleMailKit显示邮件发送,但没有收到 - .NET核心1.1

static void Main(string[] args) 
{ 
    try 
    { 
     //From Address 
     string FromAddress = "[email protected]"; 
     string FromAdressTitle = "Email from ASP.NET Core 1.1"; 
     //To Address 
     string ToAddress = "[email protected]"; 
     string ToAdressTitle = "Microsoft ASP.NET Core"; 
     string Subject = "Hello World - Sending email using ASP.NET Core 1.1"; 
     string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks (Windows, Linux, Mac) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end."; 

     //Smtp Server 
     string SmtpServer = "smtp.live.com"; 
     //Smtp Port Number 
     int SmtpPortNumber = 587; 

     var mimeMessage = new MimeMessage(); 
     mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress)); 
     mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress)); 
     mimeMessage.Subject = Subject; 
     mimeMessage.Body = new TextPart("plain") 
     { 
      Text = BodyContent 

     }; 

     using (var client = new SmtpClient()) 
     { 

      client.Connect(SmtpServer, SmtpPortNumber, false); 
      // Note: only needed if the SMTP server requires authentication 
      // Error 5.5.1 Authentication 
      client.Authenticate(FromAddress, "myFromEmailpassword"); 
      client.Send(mimeMessage); 
      Console.WriteLine("The mail has been sent successfully !!"); 
      Console.ReadLine(); 
      client.Disconnect(true); 

     } 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 

回答

1

最后,一个小时后,我收到了我的雅虎帐户的电子邮件。不知道为什么雅虎花了一个多小时,但后者发送它马上。感谢那些可能试图帮助但可能没有在代码中发现错误的人。

观察:在接收到的电子邮件可以想见,在To领域ToAdressTitleMicrosoft ASP.NET Core(从代码预期上文)。但在From字段我只看到FromAddress而不是如FromAdressTitleEmail from ASP.NET Core 1.1(在上面的代码示出)。我想知道为什么?

+0

雅虎和其他网络邮件服务器有时会重新写从头。此外,MailKit无法控制雅虎发送邮件需要多长时间 - 应该不需要一个小时,但谁知道雅虎邮箱正在做什么? – jstedfast

相关问题