The SMTP server requires secure connection or the client does not pass authentication for each solution (C #)

Source: Internet
Author: User
Tags mailmessage smtpclient

Recently, I am working on the mail sending interface to inform everyone of the problems and solutions I have encountered. I hope it will be helpful to those who know the mail.

Some code of the original program is as follows:
// Set the sender address, recipient address, title, and topic of the email.
Mailmessage mail = new mailmessage ("xxxxxxx@sina.com", "zzzzzzz@sina.com", "title", "topic ");
// Set the subject format
Mail. bodyencoding = encoding. utf8;
// Set whether the subject format is html
Mail. isbodyhtml = false;

// Verify the email user name and password
Networkcredential work = new networkcredential ("xxxxxxx", "PWD ");
// Verify the user name and password
Client. Credentials = work;

// Set the SMTP server port for the mailbox
Smtpclient client = new smtpclient ("smtp.sina.com ");
 
// Whether the request is sent together
Client. usedefacrecredentials = false;
// Set the mail sending format
Client. deliverymethod = smtpdeliverymethod. Network;
// Security connection settings
Client. enablessl = false;

Client. Send (Mail );

Error 1:
"/" Indicates a server error in the application.
--------------------------------------------------------------------------------

The SMTP server requires a secure connection or the client has not passed authentication. Server Response: 5.7.1 client was not authenticated
Note: unprocessed exceptions occur during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.

Exception details: system. net. Mail. smtpexception: the SMTP server requires a secure connection or the client has not passed authentication. Server Response: 5.7.1 client was not authenticated

Solution:
// Set the SMTP server port for the mailbox
Smtpclient client = new smtpclient ("smtp.sina.com", 587 );
Solution: I added the port number. 587 is the mail sending port. This error usually occurs when the receiver of 163 is set to QQ!

Error 2:
"/" Indicates a server error in the application.
--------------------------------------------------------------------------------

The server does not support secure connections.
Note: unprocessed exceptions occur during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.

Exception details: system. net. Mail. smtpexception: the server does not support secure connections. An error occurred when I set // Security connection to client. enablessl = true;

Solution: Set "client. enablessl = false" or remove this code.
Method 2 enable the Secure Connection Service

Error 3:
The SMTP server requires a secure connection or the client has not passed authentication. Server Response: Authentication Required
Stack trace:
[Smtpexception: the SMTP server requires a secure connection or the client has not passed authentication. Server Response: authentication required]

Solution:
Client. enablessl = false; changed to client. enablessl = true; but after this, "Error 2" may appear, So solve the problem.
First, ensure that the server supports secure connections.
This may be useful to you http://bbs.weiphone.com/read-htm-tid-1351658.html

Error 4:
The SMTP server requires a secure connection or the client has not passed authentication. The server response is:
5.7.0 must issue a starttls command first. 9sm5225813ywf. 35

Solution: Sina requires that you use SSL connections to change the value to true.
 

 

Universal solution:
1. Enter the POP3 and SMTP servers correctly.
2. The server port must be correct.
3. My server requires Identity Authentication
4. the user name and password for sending the email must be correct.

// Set the SMTP server port for the mailbox
Smtpclient client = new smtpclient ("smtp.sina.com", 587 );
163 is the most stubborn! Please note that it is best to use QQ! Haha

Sometimes the cause of mail rejection provides the following solution: http://zhidao.baidu.com/question/153511377.html

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.