Introduction to mvc3 webmail email sending

Source: Internet
Author: User
Tags mailmessage smtpclient

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.