. NET call QQ mailbox Send mail

Source: Internet
Author: User
Tags email account mailmessage smtpclient

Say the e-mail sent a lot of code, but I am not careful, resulting in someone else's code to send mail always fail, today say a few things to pay attention to it!!!

       public bool SendEmail () {mailmessage msg = new MailMessage (); Msg. To.add ("[email protected]");//Recipient address Msg. Cc. Add ("[email protected]");//CC person address Msg. from = new MailAddress ("[email protected]", "Edward");//sender mailbox, name MSG. Subject = "This was a test email from QQ";//message header MSG. subjectencoding = encoding.utf8;//header format is UTF8 msg. BODY = "This is body";//message content Msg.            bodyencoding = encoding.utf8;//content format is UTF8 smtpclient client = new SmtpClient (); Client. Host = "smtp.qq.com";//smtp server address client. Port = 587;//smtp, QQ mailbox fill 587 client. Enablessl = true;//Enable SSL encryption//Sender email account, Authorization code (note here, is the authorization code you need to go to the QQ mailbox point set to open the SMTP service, and then you will be prompted to enter the password at the third party login) CLI Ent.                   Credentials = new System.Net.NetworkCredential ("[email protected]", "password"); try {client.          Send (msg);//e-mail}  catch (Exception) {return false;        } return true; }

There's a lot of code like this code on the Web, but Most of them speak of the client. Credentials = new System.Net.NetworkCredential ("[Email protected]", "password") This piece is written in password, In fact, perhaps before the predecessors of the QQ mailbox need is the password, but now the QQ mailbox is the authorization code, the following said how to get this authorization code it!

First send a message to open an SMTP service (PS: I am still not a novice until recently, but it seems that Outlook is not SMTP, anyway, a lot of protocol)

The first step: Open the QQ mailbox click Settings:

And then two more steps, and you're done.

Step Two: Click on the Account

Step three: Pull down to locate the SMTP word, and then turn it all on

Believe you can understand this sentence, and then you open the time will automatically eject the authorization code, if there is no copy and paste at that time can click Generate authorization Code , to regenerate:

This is the east, take this copy paste to your code password place can (PS: This rookie is the pit of very miserable ah, say more a sentence 163 of the mailbox is like this, only open the SMTP service to get authorization code)

. NET call QQ mailbox Send mail

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.