In order to see how to create a .NET Core Web Application with Razor Pages and retrieve data from SQL Server using Entity Framework, you can visit my previous article.
Below are the softwares/concepts used in this document.
- Visual Studio 2019
- Razor Pages
- .Net Core 2.0
- Net Core Web Application
- C# Language
Razor pages in .NET Core 2.0 onwards have a library that we used to have in the .NET Framework to send emails (System.Net.Mail). That means there is no longer any need to rely on third party libraries or services for email functionality in your .NET Core applications.
Open your project in Visual Studio 2019
In my case, I am opening the earlier created project where Razor pages are present.

Send Email using System.Net.Mail
Open the Razor page, from which you want to send an email. In my example, I am opening Index.cshtml under “Customers” folder where my customer data is displayed.
- Create a new class to hold the properties for email.
- namespace ABC.Test
- {
- public class EmailMessage
- {
- public string To { get; set; }
- public string From { get; set; }
- public string Subject { get; set; }
- public string Body { get; set; }
- }
- }
- Create an instance of the newly created class on the page where you want to execute the email functionality. In my scenario, I am opening Index.cshtml.cs page. Also, using the BindProperty along with the instance.
- public class IndexModel : PageModel
- {
- private readonly ScaffModels.TestingCLRContext _context;
- public IndexModel(ScaffModels.TestingCLRContext context)
- {
- _context = context;
- }
- [BindProperty]
- public EmailMessage email { get; set; }



Laxmidhar SahooPosted May 8, 2019, 12:24 AM
Sir Thanks for good narration on .net core
Joe ThomasPosted May 6, 2019, 11:01 PM
What is ScaffModel? It is giving me a compilation error? is it a C# namespace?