Sending mail using SmtpClient in .net

前端 未结 5 1448
一整个雨季
一整个雨季 2021-02-07 02:19

I am unable to send the mail using smtp client. here is the code:

SmtpClient client=new SmtpClient(\"Host\");
client.Credentials=new NetworkCredential(\"username         


        
5条回答
  •  广开言路
    2021-02-07 02:50

    The short answer : Do not use .net the internal SMTP client class - use MailKit.

    The long answer :

    1. It is marked as obsolete in MS docs

    [System.Obsolete("SmtpClient and its network of types are poorly designed, we strongly recommend you use https://github.com/jstedfast/MailKit and https://github.com/jstedfast/MimeKit instead")] public class SmtpClient : IDisposable

    1. Use the oss lib MailKit.
    2. Elaboration : Because you will face its deficiencies sooner rather than later. Read here or read around the internet.
    3. Here is an example for sending plain messages and multipart messages.

    I intentionally did not copy-paste the examples from the docs here because the documentation may change over time and it is better to read .

提交回复
热议问题