In this article, we will demonstrate how to write ASP.NET to send emails. This will be discussed to, such as Email format, priority, accessories, and mail encryption.
ASP.NET sends a message by using the SMTPMail object. The SMTPMAIL object sends a message to be done by the following steps.
# Import the namespace associated with Mail.
# Create a Message object and set the properties.
# Send an email through the 'Send' method of the SMTPMail object instance.
Now let's take a step by step to learn about the process of sending an email from the ASP.NET page.
I. Import Name Space
Import the System.Web.util namespace in the ASP.NET page, which contains all objects that send mail. These objects are:
Object Introduction SMTPMail Declaration Mail System (Mail System) to send emails. MailMessage declares a message, contains attributes such as sending addresses, receive addresses. MailFormat declared the format of the message - html, text, etc. MaiLattachment declares an accessory of the email. Mailencoding Enum declaration encryption method: base64 or uuencode. MailPriority Enum Setting up the priority level: Value: High, bottom, general
<% @Import namespace = "system.web.util"%> II. Initializing MailMessage objects Using the following statement can implement the initialization MailMessage object. The DIM Mailobj AS New MailMessage MailMessage object has the following properties.
Topic BodyEmail email address SubjectEmail attribute description From the sender's email address To recipient content CCList of recipients copied on the emailBCCList of recipients blind-copied on high the emailPriority message priority, a bottom, generally BodyEncoding encrypted message content Base64 Or UUENCODEBODYFORMAT contents HTML or text attachments attachment list
The following lines of code demonstrate how to use the properties of the MailMessage object. He describes the message Message we will create, and this message is sent with the SMTPMAIL object. In our example, Mailobj is an instance of the MailMeessage object. Mailobj.from = "abc@mydomain.com" mailobj.to = request.form ("to") mailobj.subject = "Subject of the mail" mailobj.body = "Message of the mail" three. Sending an email to send a message to the 'Send' method of the SMTPMail object. The following code is used to send an email. SMTPMAIL.SEND (Mailobj) Finally we apply the above to a complete example. Here is written in ASP.NET C #. <% @ page language = "c #"%> <% @ Import namespace = "system.Web.util"%>