There is a need to send e-mail under ASP. But the System.Net.Mail under the framework did not implement the SmtpClient functionality (at the time, it was not, said it was ready to be incorporated into. NET core), so only three-party open source components could be searched, I found the mailkit. Project Address: Https://github.com/jstedfast/MailKit
public void Sendemailasync () { var message = new Mimem Essage (); message. From.add (New Mailboxaddress ("Anuraj", "[email protected]")); message. To.add ("Mailboxaddress" ("TTT", "[email protected]")); message. Subject = "Hello world-a mail from ASPNET Core"; message. Body = new Textpart ("plain") { &N Bsp Text = "Hello world-a mail from ASPNET Core" }; &NBS P using (var client = new SmtpClient ()) { //client. Querycapabilitiesafterauthenticating = false;Client. Connect ("smtp.test.com", +, FALSE); Client. Authenticationmechanisms.remove ("XOAUTH2"); Note:since we don ' t have a OAuth2 token, disableThe XOAUTH2 authentication mechanism. Client. Authenticate ("[email protected]", "Testpassword"); Client. Send (message); Client. Disconnect (TRUE); }
Very simple Synchronous code example (also has the asynchronous method to be available), the yellow highlight code, is the code which searches from the net does not have, if commented out, I use the company's server to send the mail to fail, then searches on the net, found someone uses Aliyun mailbox, also failed, and gave the plan.
Http://www.cnblogs.com/dudu/p/5661267.html
Said to be after the validation passed, sent the EHLO, resulting in authentication failure. As I look at the time, the version has been updated to the 1.12 version, so I downloaded the version of the Code, tracking, and sure enough is the cause of this
if (response. StatusCode = = smtpstatuscode.authenticationsuccessful) {if (querycapabilitiesafterauthenticating)Ehlo (CancellationToken);Authenticated = true;
If querycapabilitiesafterauthenticating = False, should not send CancellationToken, and then test the next, sure enough to send normally, and, this Querycapabilitiesafterauthenticating is a public property, so it's no problem to set it directly to false.
An analysis of the failure point of ASP. NET core using Mailkit