Last post Jun 28, 2017 11:44 PM by NewToDotyNet
Jun 23, 2017 07:12 AM|NewToDotyNet|LINK
Hi, from previous enquiry about sending email with Core MVC.
How is the email code called?
Jun 23, 2017 08:04 AM|Edward Z|LINK
For this requirement, you could try below code:
1. SendEmail method in HomeController.
public void SendEmail()
string FromAddress = "email@example.com";
string FromAdressTitle = "Email from ASP.NET Core 1.1";
string ToAddress = "firstname.lastname@example.org";
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.";
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
Console.WriteLine("The mail has been sent successfully !!");
catch (Exception ex)
2. View to call this method.
<a asp-controller="Home" asp-action="SendEmail" >Send Email</a>
Jun 24, 2017 07:39 AM|rajeeshmenoth|LINK
You can use MailKit libraries to send email in ASP.NET Core.
Source Code Download :
Jun 24, 2017 02:50 PM|NewToDotyNet|LINK
Hi Edward, this doesnt seem to work. It doent send an email and it looks for a page
That does not exist? Thanks,
Jun 26, 2017 02:07 AM|Edward Z|LINK
I would suggest you debug your code line by line to check whether you got any exception due to the wrong configuration for MimeMessage. You could comment out try catch block.
>> it looks for a page
For this, I suggest you check the difference between your current code and mine. Please pay attention to the “void” which is not “IActionResult”.
Jun 28, 2017 11:44 PM|NewToDotyNet|LINK
Hi, I had to clear the project on the server and redeploy.
It then started working online. Thanks,