MailKit 显示已发送但未收到的邮件 - .NET Core 1.1
MailKit shows mail sent but not received - .NET Core 1.1
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;
}
}
终于,一个小时后,我在我的雅虎帐户上收到了电子邮件。不知道为什么 yahoo 花了一个多小时,但 outlook 立即发送了它。感谢那些可能尝试提供帮助但可能没有发现代码错误的人。
Observation:在收到的电子邮件中,我可以看到,在 To
字段中 ToAdressTitle
as Microsoft ASP.NET Core
(正如预期的那样上面的代码)。但是在 From
字段中,我只看到 FromAddress
而不是 FromAdressTitle
作为 Email from ASP.NET Core 1.1
(如上面的代码所示)。我想知道为什么?
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;
}
}
终于,一个小时后,我在我的雅虎帐户上收到了电子邮件。不知道为什么 yahoo 花了一个多小时,但 outlook 立即发送了它。感谢那些可能尝试提供帮助但可能没有发现代码错误的人。
Observation:在收到的电子邮件中,我可以看到,在 To
字段中 ToAdressTitle
as Microsoft ASP.NET Core
(正如预期的那样上面的代码)。但是在 From
字段中,我只看到 FromAddress
而不是 FromAdressTitle
作为 Email from ASP.NET Core 1.1
(如上面的代码所示)。我想知道为什么?