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