Sometimes the traditional solution of email verification is required for projects:
Public void sendresetpasswordemail (string email ){
Mailaddress from = new mailaddress ("XXX@126.com", "Mercury"); // enter the email address and display name
Mailaddress to = new mailaddress (email, email); // enter the recipient address and name of the email.
// Set the Sending address and Receiving address. The Receiving address can be multiple
Mailmessage mail = new mailmessage ();
Mail. From = from;
Mail. to. Add ();
Mail. Subject = "topic content ";
Mail. Body = "hello ";
Mail. isbodyhtml = true; // set to display htmls
// Set the mail service address
Smtpclient client = new smtpclient ();
Client. Host = "smtp.126.com ";
// Enter the user name and password related to the server address
Client. Credentials = new system. net. networkcredential ("service", "123456 ");
// Send an email
Client. Send (Mail );
}
// The above is the traditional method, and the transmission method of mvc3 is similar. Let's take a look.
[1]. Configure mail sending Parameters
// The Name Of The SMTP server that sent the email
Webmail. smtpserver = "smtp.gmail.com ";
// Sending Port
Webmail. smtpport = 25;
// Enable SSL (required by Gmail), not required by others
Webmail. enablessl = true;
// ----------- Configuration
// Account name
Webmail. Username = "hedywqy ";
// Mailbox name
Webmail. From = "***** @ gmail.com ";
// Password
Webmail. Password = "*****";
// Set the default configuration
Webmail. smtpusedefaultcredentials = true;
----------------------------------------------------------------------
[2. send an email]
Webmail. Send (
To: xxxx@qq.com, // specifies the address
Subject: "Test Title 1", // Title
Body: "happy every day" // content
// CC: "cc ",
// Filestoattach: NULL,
// Isbodyhtml: True,
// Additionalheaders: New String [] {"AAA", "BBB "}
);
The conclusion is that using the Gmail server will slow down the sending speed by about 10 s, so we recommend using 126, 163, and so on will be faster, and I will only receive it in 1 s for my own test ..
-------------------------------------------------------------------
The following is the parsing of some parameter configurations:
email header or part |
property |
attachment |
attachments |
BCC |
BCC |
CC) |
CC |
content type |
bodyencoding |
Custom header encoding |
headersencoding |
email body |
body |
priority |
priority |
recipient |
to |
reply-to |
replytolist |
sender |
from |
Topic |
Subject |
Some of them are complete use of. Net 4.0. You can use the following classes for more control.
smtpclient class is used to send emails to the SMTP server for transmission. The classes shown in the following table can be constructed using smtpclient emails sent.
class |
description |
attachment |
Indicates the file attachment. This class allows you to attach files, streams, or text to an email. |
mailaddress |
The email address of the sender and recipient. |
mailmessage |
Indicates email. |