DEV Community

loading...

Send email with MailKit in .NET

Joe Enos
Software developer/architect, mostly working with .NET and SQL Server.
・1 min read

.NET Framework used to use SmtpClient, which read this from the app.config/web.config file:

<mailSettings>
    <smtp deliveryMethod="Network">
      <network host="my-host" 
               port="587" 
               userName="my-user"
               password="my-password" 
               enableSsl="true"
               defaultCredentials="false" 
      />
    </smtp>
</mailSettings>
Enter fullscreen mode Exit fullscreen mode

Microsoft has deprecated SmtpClient, and they recommend a library like MailKit.

MailKit is a little more verbose than the old way, but it's still reasonably straightforward. Here's how to use it:

Discussion (0)