WebMail Helper
The WebMail Helper makes sending mail easier by following SMTP (Simple Mail Transfer Protocol Simple Mail Transfer Protocol) from a web application.
Prerequisite: Email Support
To demonstrate how to use email, we will create an input page that lets the user submit one page to another and send an email about a support issue .
First: Edit your AppStart page
If you have created the Demo application in this tutorial, then you already have a page named _AppStart.cshtml with the following content:
_
AppStart.cshtml @{WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);}
To start the WebMail helper, add the following WebMail properties to your AppStart page:
_AppStart.cshtml @{WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);WebMail.SmtpServer = "smtp.example.com";WebMail.SmtpPort = 25;WebMail.EnableSsl = false;WebMail.UserName = "support@example.com";WebMail.Password = "password-goes-here";WebMail.From = "john@example.com";}
Property explanation:
SmtpServer: The name of the SMTP server used to send emails.
SmtpPort: The port used by the server to send SMTP transactions (email).
EnableSsl: If the server uses SSL (Secure Socket Layer) encryption, the value is true.
UserName: The name of the SMTP email account used to send emails.
Password: Password for the SMTP email account.
From: The email displayed in the From address field (usually the same as UserName).
Second: Create an email input page
Then create an input page and name it Email_Input:
Email_Input.cshtmlRequest for Assistance
The purpose of the input page is mobile phone information, and then Submit the data to a new page where the information can be sent as an email.
Third: Create an email sending page
Then create a page for sending emails and name it Email_Send:
Email_Send.cshtml @{ // Read inputvar customerEmail = Request["customerEmail"];var customerRequest = Request["customerRequest"];try{// Send email WebMail.Send(to:"someone@example.com", subject: "Help request from - " + customerEmail, body: customerRequest ); }catch (Exception ex ){@ex }}
[Related recommendations]
2.Share ASP.NET study notes (1)--WebPages Razor
3.Share ASP.NET study notes (2)--WebPages introduction
4.Share ASP.NET study notes (3) WebPages layout
5.Share ASP.NET study notes (7) Detailed explanation of WebPages objects
6.Share ASP.NET study notes (5) Global page AppStart and PageStart
7.Share ASP.NET study notes (8) WebPages Helper
The above is the detailed content of Share ASP.NET study notes (10) WebPages Email. For more information, please follow other related articles on the PHP Chinese website!