{"id":21681,"date":"2024-03-25T19:22:00","date_gmt":"2024-03-25T18:22:00","guid":{"rendered":"https:\/\/kunskap.websupport.se\/kb\/sending-emails-via-net\/"},"modified":"2024-03-25T19:22:00","modified_gmt":"2024-03-25T18:22:00","slug":"sending-emails-via-net","status":"publish","type":"ht_kb","link":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/","title":{"rendered":"Sending emails via .NET"},"content":{"rendered":"\n<p>To send e-mail using ASP.NET, you can use the System.Net.Mail library. Here you will find examples of code that can be used for this.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"skicka-text-meddelande\">Send a text message<\/h2>\n\n<p>If you want to send e-mail messages, formatted as plain text, through ASP.NET, you need to use the System.Net.Mail library. Here you can access some simple functions of the MailMessage and SMTPClient classes.<\/p>\n\n<pre class=\"wp-block-code\"><code>&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" %>\n&lt;%@ Import Namespace=\"System.Net.Mail\" %>\n&lt;%\n MailMessage mail = new MailMessage();\n mail.From = new MailAddress(\"info@mindoman.se\");\n mail.To.Add(\"min.epost@mindoman.se\");\n mail.Subject = \"Testmeddelande\";\n mail.Body = \"Detta \u00e4r inneh\u00e5llet i meddelandet.\";\n SmtpClient smtp = new SmtpClient(\"smtp.websupport.se\");\n smtp.Port = 587;\n try\n {\n smtp.Send(mail);\n }\n catch (Exception ex)\n {\n Response.Write(\"Caught exception: \" + ex.ToString());\n }\n%><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"skicka-html-meddelande\">Send HTML message<\/h2>\n\n<p>It is easy to send the message as HTML instead. All you need to do is set mail.IsBodyHtml to true and then use HTML in mail.Body.<\/p>\n\n<pre class=\"wp-block-code\"><code>&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" %>\n&lt;%@ Import Namespace=\"System.Net.Mail\" %>\n&lt;%\n MailMessage mail = new MailMessage();\n mail.From = new MailAddress(\"info@mindoman.se\");\n mail.To.Add(\"min.epost@mindoman.se\");\n mail.Subject = \"Testmeddelande\";\n mail.Body = \"&lt;em style=\\\"color: #f11;\\\">Detta \u00e4r inneh\u00e5llet i meddelandet.&lt;\/em>\";\n mail.IsBodyHtml = true;\n SmtpClient smtp = new SmtpClient(\"smtp.websupport.se\");\n smtp.Port = 587;\n try\n {\n smtp.Send(mail);\n }\n catch (Exception ex)\n {\n Response.Write(\"Caught exception: \" + ex.ToString());\n }\n%><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"skicka-e-post-med-autentiserad-anvandare\">Send emails with an authenticated user<\/h2>\n\n<p>When sending emails, it is recommended to authenticate to the SMTP server to avoid the message being classified as spam. This requires the inclusion of the System.Net library containing the NetworkCredential class.<\/p>\n\n<pre class=\"wp-block-code\"><code>&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" %>\n&lt;%@ Import Namespace=\"System.Net\" %>\n&lt;%@ Import Namespace=\"System.Net.Mail\" %>\n&lt;%\n MailMessage mail = new MailMessage();\n mail.From = new MailAddress(\"info@mindoman.se\");\n mail.To.Add(\"min.epost@mindoman.se\");\n mail.Subject = \"Testmeddelande\";\n mail.Body = \"&lt;em style=\\\"color: #f11;\\\">Detta \u00e4r inneh\u00e5llet i meddelandet.&lt;\/em>\";\n mail.IsBodyHtml = true;\n SmtpClient smtp = new SmtpClient(\"smtp.websupport.se\");\n smtp.Port = 465;\n smtp.Credentials = new NetworkCredential(\"info@mindoman.se\", \"l\u00f6senord\");\n try\n {\n smtp.Send(mail);\n }\n catch (Exception ex)\n {\n Response.Write(\"Caught exception: \" + ex.ToString());\n }\n%><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"skicka-e-post-med-autentiserad-anvandare-ssl\">Send email with authenticated user + SSL<\/h2>\n\n<p>To enable SSL, use the smtp.EnableSsl component set to true.<\/p>\n\n<pre class=\"wp-block-code\"><code>&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" %>\n&lt;%@ Import Namespace=\"System.Net\" %>\n&lt;%@ Import Namespace=\"System.Net.Mail\" %>\n&lt;%\n    MailMessage mail = new MailMessage();\n    mail.From = new MailAddress(\"info@mindoman.se\");\n    mail.To.Add(\"min.epost@mindoman.se\");\n    mail.Subject = \"Testmeddelande\";\n    mail.Body = \"&lt;em style=\\\"color: #f11;\\\">Detta \u00e4r inneh\u00e5llet i meddelandet.&lt;\/em>\";\n    mail.IsBodyHtml = true;\n    SmtpClient smtp = new SmtpClient(\"smtp.websupport.se\");\n    smtp.Port = 465;\n    smtp.Credentials = new NetworkCredential(\"info@mindoman.se\", \"l\u00f6senord\");\n    smtp.EnableSsl = true;\n    try\n    {\n        smtp.Send(mail);\n    }\n    catch (Exception ex)\n    {\n        Response.Write(\"Caught exception: \" + ex.ToString());\n    }\n%><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To send e-mail using ASP.NET, you can use the System.Net.Mail library. Here you will find examples of code that can be used for this. Send a text message If you want to send e-mail messages, formatted as plain text, through ASP.NET, you need to use the System.Net.Mail library. Here you&#8230;<\/p>\n","protected":false},"author":45,"template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[465],"ht-kb-tag":[],"class_list":["post-21681","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-windows-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sending emails via .NET - Websupport kunskapsdatabas<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sending emails via .NET - Websupport kunskapsdatabas\" \/>\n<meta property=\"og:description\" content=\"To send e-mail using ASP.NET, you can use the System.Net.Mail library. Here you will find examples of code that can be used for this. Send a text message If you want to send e-mail messages, formatted as plain text, through ASP.NET, you need to use the System.Net.Mail library. Here you...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/\" \/>\n<meta property=\"og:site_name\" content=\"Websupport kunskapsdatabas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/\",\"url\":\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/\",\"name\":\"Sending emails via .NET - Websupport kunskapsdatabas\",\"isPartOf\":{\"@id\":\"https:\/\/kunskap.websupport.se\/en\/#website\"},\"datePublished\":\"2024-03-25T18:22:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kunskap.websupport.se\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sending emails via .NET\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kunskap.websupport.se\/en\/#website\",\"url\":\"https:\/\/kunskap.websupport.se\/en\/\",\"name\":\"Websupport kunskapsdatabas\",\"description\":\"Websupport kunskapsdatabas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kunskap.websupport.se\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sending emails via .NET - Websupport kunskapsdatabas","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/","og_locale":"en_US","og_type":"article","og_title":"Sending emails via .NET - Websupport kunskapsdatabas","og_description":"To send e-mail using ASP.NET, you can use the System.Net.Mail library. Here you will find examples of code that can be used for this. Send a text message If you want to send e-mail messages, formatted as plain text, through ASP.NET, you need to use the System.Net.Mail library. Here you...","og_url":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/","og_site_name":"Websupport kunskapsdatabas","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/","url":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/","name":"Sending emails via .NET - Websupport kunskapsdatabas","isPartOf":{"@id":"https:\/\/kunskap.websupport.se\/en\/#website"},"datePublished":"2024-03-25T18:22:00+00:00","breadcrumb":{"@id":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kunskap.websupport.se\/en\/kb\/sending-emails-via-net\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kunskap.websupport.se\/"},{"@type":"ListItem","position":2,"name":"Sending emails via .NET"}]},{"@type":"WebSite","@id":"https:\/\/kunskap.websupport.se\/en\/#website","url":"https:\/\/kunskap.websupport.se\/en\/","name":"Websupport kunskapsdatabas","description":"Websupport kunskapsdatabas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kunskap.websupport.se\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb\/21681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/users\/45"}],"version-history":[{"count":1,"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb\/21681\/revisions"}],"predecessor-version":[{"id":21682,"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb\/21681\/revisions\/21682"}],"wp:attachment":[{"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/media?parent=21681"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb-category?post=21681"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kunskap.websupport.se\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=21681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}