Application system sending emails is a basic function, almost all website applications will need to send emails, such as: email registration verification, push reminder messages, sending password recovery links, etc.
Using Microsoft's own SmtpClient class can help us send emails, but now it has been marked as obsolete, and Microsoft has not given its own alternatives, so it is recommended to use third-party libraries, as shown in the figure below:
Allow applications to use Simple Mail Transfer Protocol (SMTP) to send email. The SmtpClient type is now obsolete.
The SmtpClient class is not recommended for new development, as SmtpClient does not support many modern protocols. Use MailKit or another library instead.
Link:The hyperlink login is visible.
Recap of sending emails with Microsoft SMTPclient:
Sending emails using Microsoft's smtpclient may result in an error:Authentication failed, however, both the account and password are correct!
This article uses Microsoft's third-party library MailKit to send emails, first, use nuget to install with the following command:
The sending code is as follows:
I wrote a winform applet to facilitate testing on the server, as shown in the figure below:
SmtpHost= "smtp.exmail.qq.com", EnableSsl =true, Password= "pass123456", Port= 587, UserName= "itsvse@baidu.com" Try sending an email as shown below:
Attach the source code and procedure:
Tourists, if you want to see the hidden content of this post, please Reply
|