May 12, 2021 ASP.NET
1. ASP.NET Web Pages - WebMail object
3. WebMail Object Reference Manual - Properties
4. WebMail Object Reference Manual - Method
WebMail objects make it easy to send e-mail from Web pages.
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.
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). |
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 |
name | value |
---|---|
Class | System.Web.Helpers.WebMail |
Namespace | System.Web.Helpers |
Assembly | System.Web.Helpers.dll |
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:
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:
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.
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. |