VS2017
中的C#代码显示邮件已成功发送。我可以从我的outlook
帐户的已发信息框中验证电子邮件确实已成功发送。但是在我的Yahoo
帐户上,即使超过一个小时,电子邮件也不存在。 问题:我的代码中缺少某些内容 - 我们如何才能使其有效? 注意:我已在Outlook的已发送框中验证了From
和To
邮件地址均正确无误。我正在关注Technet article。
static void Main(string[] args)
{
try
{
//From Address
string FromAddress = "myfromEmail@hotmail.com";
string FromAdressTitle = "Email from ASP.NET Core 1.1";
//To Address
string ToAddress = "myToEmail@yahoo.com";
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;
}
}
答案 0 :(得分:1)
最后,一小时后,我收到了我的雅虎帐户上的电子邮件。不知道为什么雅虎需要花费一个多小时,但前景立即发送。感谢那些可能试图帮助但可能没有在代码中发现错误的人。
观察:在收到的电子邮件中,我可以在To
字段中看到ToAdressTitle
为Microsoft ASP.NET Core
(正如上面代码所预期的那样)。但是在From
字段中,我只看到FromAddress
而不是FromAdressTitle
作为Email from ASP.NET Core 1.1
(如上面的代码所示)。我想知道为什么?