C # implements Simple mail sending code as follows
Public Static voidSendAsync (stringEmailto,stringSubjectstringmailbody) { varmsg =NewMailMessage (); Msg. To.add (Emailto); //Msg. from =NewMailAddress (_usernameforemail,"Sender name displayed", System.Text.Encoding.UTF8); Msg. Subject= subject;//message HeaderMsg. Subjectencoding =System.Text.Encoding.UTF8; Msg. Body= Mailbody;//Message ContentMsg. Bodyencoding =System.Text.Encoding.UTF8; Msg. Isbodyhtml=false; Msg. Priority= Mailpriority.high;//Message Priority// varClient =NewSmtpClient (); Client. useDefaultCredentials=false; Client. Credentials=NewNetworkCredential (_usernameforemail, _passwordforemail); //Client. Host =_smtphost; Try { //simply a little bit can be client. Send (msg); client. Send (msg); //Task.Factory.StartNew (() =//{ //client. Send (msg); //}); //client. SendAsync (msg, userState); } Catch(Smtpexception ex) {
Log. Error (ex); Throwex; } }
When you pass in the correct user name and password for the sending mailbox, you always receive: The mailbox is unavailable. has no permission such error, English error: Mailbox unavailable. The server response Was:user has no permission.
Actually, we use. NET sends a message when the custom client logs in based on the user name and password, and then uses the SMTP service to send the message. However, the newly registered 163 messages are not turned on by default for Client authorization verification (default on for custom mailbox master clients),
Therefore the login is always rejected, and authentication does not have permissions. The solution is to enter 163 mailbox, enter the mailbox center-the client authorization password, choose to open, as follows
After the setup is complete, use the client authorization password in your code instead of the original mailbox password, so that you can send the message correctly.
. NET error when sending mail using 163SMTP: The mailbox is not available. has no permission solution