We often see that you can post comments on some blog pages and notify the moderator via email (for example, our blog Park). So how can I use Asp.net to send emails? We can achieve this with the powerful class libraries provided by. net.
First, we need to introduce the system. Web. Mail namespace.
Create an instance of the mailmessage class. See belowCode:
1' create an instance
2dim objmm as new mailmessage ()
3
4 'set its properties
5objmm. To = "someone@someaddress.com"
6objmm. From = "someoneelse@someotheraddress.com"
7objmm. Cc = "someone2@someaddress.com"
8objmm. bcc = "someoneElse@someaddress.com"
9
10' sent in text format
11objmm. bodyformat = mailformat. Text
12' or sent in HTML Format
13objmm. bodyformat = mailformat. html
14
15' set mail priority
16objmm. Priority = mailpriority. Normal
17
18 'set theme
19objmm. Subject = "Hello there! "
20' mail body
21objmm. Body = "Hi! "& Vbcrlf &" How are you doing? "
22
'Finally, use the static method of the smtpmail class to send smtpmail. Send (objmm)
Some email servers need to authenticate the email again when sending the email (generally to prevent the spread of spam mail), for example, 163 free mailbox, if it is a version later than. net1.1, you can add:
Objmm. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); // Basic Authentication
Objmm. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "your_username_here"); // set your Username
Objmm. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "your_password_here"); // set your password
In ASP. net2.0, The mailmessage class has been moved to the system. net. Mail namespace. For details about how to send emails, see:
Http://aspnet.4guysfromrolla.com/articles/072606-1.aspx
Http://aspnet.4guysfromrolla.com/articles/080206-1.aspx
Sending HTML mail with embedded image in. net
In addition, we will introduce a website dedicated to system. Web. mail:
Http://www.systemwebmail.com/default.aspx
For. net2.0, visit the system. net. Mail URL:
Http://www.systemnetmail.com/