Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET web Pages WebMail reference manual


May 12, 2021 ASP.NET


Table of contents


ASP.NET Web Pages - WebMail object

This section explains The properties of the WebMail object, how, and how to initialize the WebMail helper.

WebMail objects make it easy to send e-mail from Web pages.


Describe

WebMail objects provide ASP.NET the ability to send messages using SMTP ( Simple Mail Transfer Protocol Transfer Protocol) for web pages.


Check out the instances in the WebPages Email section.


WebMail Object Reference Manual - Properties

Attributes describe
SmtpServer The name of the SMTP server used to send an email.
SmtpPort The server is used to send the port of the SMTP email.
EnableSsl The value is true if the server encrypts using the SSL (Secure Socket Layer Security Socket).
UserName The name of the SMTP email account used to send an email.
Password The password of the SMTP email account.
From Email displayed in the sender address bar (usually the same as UserName).


WebMail Object Reference Manual - Method

method describe
Send() Send email information that needs to be transmitted to the SMTP server.

The Send() method has the following parameters:

parameter type describe
to String Recipient (separated by a semicolon)
subject String Email Subject
body String Mail body

The Send() method has the following optional parameters:

parameter type describe
from String Sender
cc String Require copy email address (separated by a semicolon)
filesToAttach Collection Attachment name
isBodyHtml Boolean True is true if the body of the message is HTML format.
additionalHeaders Collection Additional title


Technical data

name value
Class System.Web.Helpers.WebMail
Namespace System.Web.Helpers
Assembly System.Web.Helpers.dll


Initialize the WebMail helper

To use the WebMail helper, you must have access to the SMTP server. S MTP is the "output" part of an e-mail message. I f you are using a virtual host, you may already know the name of the SMTP server. I f you're working on a corporate network, your company's IT department will give you a name. If you work from home, you may be able to use a regular email service provider.

In order to send an e-mail message, you will need to:

  • The name of the SMTP server
  • Port number (usually 25)
  • The user name of the e-mail message
  • The password for the e-mail message

Under your web root, create a page called _AppStart.cshtml (edit the page directly if it already exists).

Copy the following code to the file:

_AppStart.cshtml

@{
WebMail.SmtpServer = "smtp.example.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "[email protected]";
WebMail.Password = "password";
WebMail.From = "[email protected]"
}

The code above will run each time the site (application) starts. It assigns an initial value to the WebMail object.

Please replace:

Replace smtp.example.com the name of the SMTP server you want to use to send e-mail messages.

Replace 25 with the port number that the server used to send SMTP transactions (e-mail messages).

If the server is encrypted with SSL (Secure Socket Layer Security Layer), replace false with true.

Replace [email protected] the name of the SMTP e-mail account used to send e-mail messages.

Replace passwords with passwords for SMTP e-mail accounts.

Replace john@example with an e-mail message that appears in the sending address bar.

ASP.NET web Pages WebMail reference manual In your AppStart file, you don't need to start a WebMail object, but you must set these properties before calling the WebMail.Send() method.