Configuration issues with MVC 4 web-Sent messages

Source: Internet
Author: User
Tags mailmessage smtpclient

Sometimes a project needs to be sent to email for verification. Traditional solutions:

public void Sendresetpasswordemail (string email) {

MailAddress from = new MailAddress ("[email protected]", "Mercury"); Fill in e-mail address, and display name

MailAddress to = new MailAddress (email, email); Fill in the recipient address and name of the message

Set the send address, and receive address, the receive address can be multiple

MailMessage mail = new MailMessage ();

Mail. from = from;

Mail. To.add (to);

Mail. Subject = "Subject content";

Mail. Body = "Hello";

Mail. isbodyhtml = true;//Setting display htmls

Set up Send mail service address

SmtpClient client = new SmtpClient ();

Client. Host = "smtp.126.com";

Fill in the User name and password information associated with the server address

Client. Credentials = new System.Net.NetworkCredential ("Service", "123456");

Send mail

Client. Send (mail);

The above is the traditional way, MVC3 it is sent in a similar way, let's have a look.

"1", configure the parameters sent by mail

The server name of the SMTP that sent the e-mail message

Webmail.smtpserver = "smtp.gmail.com";

Send Port

Webmail.smtpport = 25;

Enable SSL (Gmail is required), no other need

Webmail.enablessl = true;

-----------Configuration

Account name

Webmail.username = "Hedywqy";

Mailbox name

Webmail.from = "* * * * * @gmail. com";

Password

Webmail.password = "* * * * *";

Setting the default configuration

Webmail.smtpusedefaultcredentials = true;

----------------------------------------------------------------------

"2, Send Mail"

Webmail.send (

To: [email protected],//address specified

Subject: "Test Title 1",//title

Body: "Happy every Day"//Content

CC: "CC",

Filestoattach:null,

Isbodyhtml:true,

Additionalheaders:new string[] {"AAA", "BBB"}

);

Summary found that the use of Gmail server, will send the speed will be very slow about about 10S, so recommended with 126, 163, etc. will be faster, I test with 163 only 1S on the received.

-------------------------------------------------------------------

Here are some parameters that are configured for parsing:

Message header or section

Property

Attachment

Attachments

Blind carbon copy (BCC)

Bcc

CC (CC)

Cc

Content Type

Bodyencoding

Encoding of custom headers

Headersencoding

Message body

Body

Priority level

Priority

Recipient

To

Reply-to

Replytolist

Sender

From

Theme

Subject

section is full use of. NET 4.0. If you want more control, you can use the following classes yourself.

The SmtpClient class is used to send e-mail messages to an SMTP server for delivery. The classes shown in the following table are used to construct e-mail messages that can be sent using SmtpClient.

Class

Description

Attachment

Represents a file attachment. This class allows you to attach files, streams, or text to an e-mail message.

MailAddress

Represents the e-mail address of the sender and recipient.

MailMessage

Represents an e-mail message.

Configuration issues with MVC 4 web-Sent messages

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.