With the WebMail object you can easily send emails from a web page.
The WebMail Object provides email for ASP.NET Web Pages using SMTP (Simple Mail Transfer Protocol).
See an example in the chapter: Web Pages Email.
| Properties | Description |
|---|---|
| SmtpServer | The name the SMTP server that will send the emails |
| SmtpPort | The port the server will use to send SMTP emails |
| EnableSsl | True, if the server should use SSL encryption |
| UserName | The name of the SMTP account used to send the email |
| Password | The password of the SMTP account |
| From | The email to appear in the from address |
| Method | Description |
|---|---|
| Send() | Sends an email message to an SMTP server for delivery |
The Send() method has the following parameters:
| Parameter | Type | Description |
|---|---|---|
| to | String | The Email recipients (separated by semicolon) |
| subject | String | The subject line |
| body | String | The body of the message |
And the following optional parameters:
| Parameter | Type | Description |
|---|---|---|
| from | String | The email of the sender |
| cc | String | The cc emails (separated by semicolon) |
| filesToAttach | Collection | Filenames |
| isBodyHtml | Boolean | True if the email body is in HTML |
| additionalHeaders | Collection | Additional headers |
| Name | Value |
|---|---|
| Class | System.Web.Helpers.WebMail |
| Namespace | System.Web.Helpers |
| Assembly | System.Web.Helpers.dll |
To use the WebMail helper, you need access to an SMTP server. SMTP is the "output" part of email. If you use a web host, you probably already know the name of the SMTP server. If you work in a corporate network, your IT department can give you the name. If you are working at home, you might be able to use your ordinary email provider.
In order to send an email you will need:
In the root of your web, create a page (or edit the page ) named _AppStart.cshtml.
Put the following code inside the file:
The code above will run each time the web site (application) starts. It feeds your WebMail Object with initial values.
Please substitute:
smtp.example.com with the name the SMTP server that will be used to send the emails.
25 with the port number the server will use to send SMTP transactions (emails).
false with true, if the server should use SSL (Secure Socket Layer) encryption.
support@example.com with the name of the SMTP email account used to send emails.
password with the password of the SMTP email account.
john@example with the email to appear in the from address.
| You don't have to initiate the WebMail object in your AppStart file, but you must set these properties before you call the WebMail.Send() method. |
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.