Reputation: 23749
Following C# code in VS2017
shows the mail was sent successfully. And I can verify from my outlook
account's sent box that the email indeed was sent successfully. But on my Yahoo
account, email is not there even after more than an hour. Question: Is something missing in my code here - how can we make it work? NOTE: I've verified in my outlook's sent box that both From
and To
mail addresses are correct. I'm following this Technet article.
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;
}
}
Upvotes: 1
Views: 1755
Reputation: 23749
Finally, after an hour, I received the email on my yahoo account. Not sure why it took more than an hour for yahoo but outlook sent it right away. Thanks to those who may have tried to help but probably did not find an error in the code.
Observation: In the received email I can see, in the To
field the ToAdressTitle
as Microsoft ASP.NET Core
(as expected from the code above). But in the From
field I see only the FromAddress
and not the FromAdressTitle
as Email from ASP.NET Core 1.1
(shown in the code above). I wonder why?
Upvotes: 1