. NET sends emails in case of problems and solutions

Source: Internet
Author: User
Tags email account mailmessage smtpclient

. NET sends emails in case of problems and solutions
. NET background Code: "mail from address must be same as authorization user"

 

First, let's take a look at my code implementation.

Background code:

Public class EmailHelper {// <summary> // send an email /// </summary> /// <param name = "subject"> topic </param> // /<param name = "body"> content </param> public static void SendEmail (string subject, string body) {var mailFrom = ConfigurationManager. deleetask[ "mailFrom"]; var mailTo = ConfigurationManager. deleetask[ "mailTo"]; var mailCC = ConfigurationManager. appSettings ["mailCC"]; var smtp = ConfigurationManager. appSettings ["smtp"]; var smtpPort = Convert. toInt32 (ConfigurationManager. deleetask[ "smtpPort"]); var emailAccount = ConfigurationManager. deleetask[ "emailAccount"]; var emailPassword = ConfigurationManager. deleetask[ "emailPassword"]; // MailMessage mailMessage MailMessage = new mailMessage {From = new MailAddress (mailFrom), Subject = subject, Body = body,}; MailMessage. to. add (mailTo); mailMessage. CC. add (mailCC );
// Configure SmtpClient smtpClient = new SmtpClient (smtp, smtpPort) {Credentials = new NetworkCredential (emailAccount, emailPassword), EnableSsl = true,} on the mailbox server ,};
// Send the smtpClient. Send (mailMessage );}}

 

Configuration file:

<Deleetask> <! -- Sender, recipient, CC --> <add key = "mailFrom" value = "53xxx1314@qq.com"/> <add key = "mailTo" value = "89xxxx734@qq.com"/> <add key = "mailCC" value = "89xxx734@qq.com"/> <! -- Mailbox server host address and port number --> <add key = "smtp" value = "smtp.qq.com"/> <add key = "smtpPort" value = "25"/> <! -- Sender's email account password --> <add key = "emailAccount" value = "53xxx1314"/> <! -- This password is not a QQ password, but a password generated by the mailbox --> <add key = "emailPassword" value = "stxxxxxxtscbbb"/> </appSettings>

 

 

The code is ready, and the rest is running.

The first problem encountered when running is "mail from address must be same as authorization user"

 

The specific reason is that my account password is correct. After reading several blog articles, I confirmed that the QQ mailbox password had a problem. However, it is normal for me to use the QQ password to log on to my mailbox. Then I tried to enable the POP/SMTP service and found the main problem.

  POP/SMTP service in QQ mail is not enabled

  

 

Procedure:

Go to QQ mail-> Settings-> account-> scroll to POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV service"

 

If it is not enabled, enable it.

I didn't enable it. After clicking it, I need to send a text message and configure the mail client

After the text message is sent, the authorization code is obtained, and the authorization code is replaced with the QQ password I wrote in the code, and then re-run, the error disappears, mainly due to unauthorized issues

Note: The authorization code will expire after the QQ password or independent password is modified and must be obtained again.

 

Run again, no problem

 

  Although the problem is not very big, and there is not much technical content, but it can save us the trouble of solving this problem again, but we cannot think of how to solve it. In retrospect, the total proportion of new attention should save time.

 

 

 

 , I hope I can come back and see my step when my technology is successful.

 

Related Article

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.