Home > Backend Development > C#.Net Tutorial > Share ASP.NET study notes (10) WebPages Email

Share ASP.NET study notes (10) WebPages Email

零下一度
Release: 2017-05-27 15:52:31
Original
1981 people have browsed it

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);}
Copy after login

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";}
Copy after login

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.cshtml
<!DOCTYPE html> <html> <body> <h1>Request for Assistance</h1> <form method="post" action="EmailSend.cshtml"> <label>Username:</label><input type="text name="customerEmail" /><label>Details about the problem:</label> <textarea name="customerRequest" cols="45" rows="4"></textarea> <p><input type="submit" value="Submit" /></p> </form> </body> </html>
Copy after login

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 ){<text>@ex</text> }}
Copy after login

[Related recommendations]

1. ASP.NET free video tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template