ASP.NET Web Pages - The WebMail Helper

The WebMail Helper - One of many useful ASP.NET Web Helpers.

The WebMail Helper

The WebMail Helper makes it easy to send an email from a web application using SMTP (Simple Mail transfer Protocol).

Scenario: Email Support

To demonstrate the use of email, we will create an input page for support, let the user submit the page to another page, and send an email about the support problem.

First: Edit Your AppStart Page

If you have built the Demo application in this tutorial, you already have a page called _AppStart.cshtml with the following content:


WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);

To initiate the WebMail helper, add the the following WebMail properties to your AppStart page:


WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);
WebMail.SmtpServer = "";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "";
WebMail.Password = "password-goes-here";
WebMail.From = "";


Properties explained:

SmtpServer: The name the SMTP server that will be used to send the emails.

SmtpPort: The port the server will use to send SMTP transactions (emails).

EnableSsl: True, if the server should use SSL (Secure Socket Layer) encryption.

UserName: The name of the SMTP email account used to send the email.

Password: The password of the SMTP email account.

From: The email to appear in the from address (often the same as UserName).

Second: Create an Email Input Page

Then create an input page, and name it Email_Input:


<!DOCTYPE html>
<h1>Request for Assistance</h1>

<form method="post" action="EmailSend.cshtml">
<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>


The purpose of the input page is to collect information, then submit the data to a new page that can send the information as an email.

Third: Create An Email Send Page

Then create the page that will be used to send the email, and name it Email_Send:


@{ // Read input
var customerEmail = Request["customerEmail"];
var customerRequest = Request["customerRequest"];
// Send email
WebMail.Send(to:"", subject: "Help request from - " + customerEmail, body: customerRequest );
catch (Exception ex )

For more information about sending emails from a ASP.NET Web Pages application, please see the: WebMail Object Reference.

Color Picker