{"id":5510,"date":"2019-07-02T12:39:39","date_gmt":"2019-07-02T10:39:39","guid":{"rendered":"https:\/\/www.limilabs.com\/blog\/?p=5510"},"modified":"2023-08-07T13:50:40","modified_gmt":"2023-08-07T11:50:40","slug":"use-tls12-with-smtp","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/use-tls12-with-smtp","title":{"rendered":"Using TLS 1.2 with .NET SMTP client"},"content":{"rendered":"\n<p>In the following article, we will provide a comprehensive guide on configuring the <a href=\"\/mail\">Mail.dll SMTP client<\/a> to utilize the TLS 1.2 encryption protocol. <\/p>\n\n\n\n<p>This security enhancement ensures that sending email communications remain safeguarded against potential threats and unauthorized access.<\/p>\n\n\n\n<p>By default clients and SMTP servers negotiate SSL\/TLS versions they can both use. Most systems don&#8217;t allow SSL 3.0, TLS 1.0, 1.1 anymore and Mail.dll SMTP component simply uses the most recent TLS version.<\/p>\n\n\n\n<p>TLS 1.2 and 1.3 are the most secure versions of TLS protocols. It is easy to force the connection to use it. <\/p>\n\n\n\n<p>All you need to do is to set <em>Smtp.SSLConfiguration.EnabledSslProtocols<\/em> property to <em>SslProtocols.Tls12<\/em> before issuing <code>ConnectSSL<\/code> or <code>Connect<\/code> and <code>StartTLS<\/code> sequence:<\/p>\n\n\n\n<div class=\"well\">Here you can <a href=\"\/blog\/use-ssl-with-smtp\">learn more on how TLS\/SSL and StartTLS work in SMTP protocol<\/a><\/div>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nusing (Smtp smtp = new Smtp())\n{\n    smtp.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;\n\n    smtp.ConnectSSL(\"smtp.example.com\");\n\n    smtp.UseBestLogin(\"user\",\"password\");\n\n    \/\/ ... \n\n    smtp.Close();\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET\n\nUsing smtp As New Smtp()\n\tsmtp.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12\n\n\tsmtp.ConnectSSL(\"smtp.example.com\")\n\n\tsmtp.UseBestLogin(\"user@example.com\", \"password\")\n\n\t'...\n\n\tsmtp.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explicit SSL\/TLS (STARTTLS)<\/h2>\n\n\n\n<p>For <a href=\"\/blog\/ssl-vs-tls-vs-starttls-stls\">explicit SSL\/TLS<\/a>, code is almost the same. You first connect to a default, non-secure SMTP email submission port (587) and secure the connection using <code>Smtp.StartTLS<\/code> method:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nusing (Smtp smtp= new Smtp())\n{\n    smtp.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;\n\n    smtp.Connect(\"smtp.example.com\");\n    smtp.StartTLS();\n\n    smtp.UseBestLogin(\"user@example.com\",\"password\");\n\n    \/\/ ... \n\n    smtp.Close();\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET\n\nUsing smtp As New Smtp()\n\tsmtp.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12\n\n\tsmtp.Connect(\"smtp.example.com\")\n\tsmtp.StartTLS()\n\n\tsmtp.UseBestLogin(\"user@example.com\", \"password\")\n\n\t'...\n\n\tsmtp.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Older .NET framework versions<\/h2>\n\n\n\n<p>To use TLS 1.2 in SMTP client at least .NET Framework 4.5+ must be installed on your machine and your application should target .NET 4.5+.<\/p>\n\n\n\n<p>It is possible to use TLS 1.2 in applications targeting earlier .NET framework versions, but 4.5 must be installed on the machine. After you have .NET 4.5 installed, your 2.0 &#8211; 4.0 app will use the 4.5 System.dll and you can enable TLS 1.2 using this code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nsmtp.SSLConfiguration.EnabledSslProtocols = \n    (SecurityProtocolType)3072;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>In the following article, we will provide a comprehensive guide on configuring the Mail.dll SMTP client to utilize the TLS 1.2 encryption protocol. This security enhancement ensures that sending email communications remain safeguarded against potential threats and unauthorized access. By default clients and SMTP servers negotiate SSL\/TLS versions they can both use. Most systems don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[50,53,83,114],"class_list":["post-5510","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-smtp","tag-ssl","tag-tls","tag-tls-1-2"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5510"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=5510"}],"version-history":[{"count":7,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5510\/revisions"}],"predecessor-version":[{"id":6527,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5510\/revisions\/6527"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=5510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=5510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=5510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}