An analysis of the failure point of ASP. NET core using Mailkit

Source: Internet
Author: User
Tags smtpclient

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

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.