{"id":527,"date":"2012-11-01T14:47:38","date_gmt":"2012-11-01T14:47:38","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=527"},"modified":"2012-12-18T20:08:59","modified_gmt":"2012-12-18T20:08:59","slug":"testing-sharepoint-outbound-e-mail","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/","title":{"rendered":"Testing SharePoint outbound e-mail"},"content":{"rendered":"<p>It\u2019s quite easy to test SMTP email from your SharePoint site, in fact from any server using the Telnet client and any of the thousands of SMTP test guides across the net.<\/p>\n<p>What isn\u2019t so easy is to test outbound email from SharePoint itself and have complete control over what\u2019s being sent. You can of course configure an alert, and hope that this will send an e-mail, but you don\u2019t have complete control of the process as you are reliant on timer jobs and other variables to process that alert.<\/p>\n<p>This is an update of an earlier blog post that I wrote about using the SPUtility class and the SendEmail method, however instead of doing this in code, we\u2019re going to use PowerShell. (<a href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/05\/using-the-undocumented-sputilitysendemail-method\/\">This is the original blog post.)<\/a><\/p>\n<p>First up, open a PowerShell session on the server containing Central Admin. In order to send an email, we need to set-up 3 objects, The headers for the e-mail, the body text and the Web that we want to associate it with.<\/p>\n<p>Firstly we use a String dictionary to create the header collection, and then add the various header nodes to it.<\/p>\n<pre class=\"csharpcode\">$sd = <span class=\"kwrd\">new<\/span>-<span class=\"kwrd\">object<\/span> System.collections.specialized.stringdictionary\r\n$sd.add(<span class=\"str\">&quot;to&quot;<\/span>,<span class=\"str\">&quot;ourrecipient@email.address&quot;<\/span>)\r\n$sd.add(<span class=\"str\">&quot;from&quot;<\/span>,<span class=\"str\">&quot;outsender@email.address&quot;<\/span>)\r\n$sd.add(<span class=\"str\">&quot;Subject&quot;<\/span>,<span class=\"str\">&quot;The clue is in the name!&quot;<\/span>)\r\n<\/pre>\n<p><style type=\"text\/css\">.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, \"Courier New\", courier, monospace; background-color: #ffffff; \/*white-space: pre;*\/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } <\/style>\n<p>Once we have the header collection, we just need to get a reference to the web object and also the body of our test message.<\/p>\n<pre class=\"csharpcode\">$web = get-spweb <span class=\"str\">&quot;http:\/\/www.myfatblog.co.uk&quot;<\/span>\r\n$body = <span class=\"str\">&quot;This is our body&lt;br\/&gt; We can use &lt;strong&gt;HTML&lt;\/strong&gt; codes in it.&quot;<\/span><\/pre>\n<p><style type=\"text\/css\">.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, \"Courier New\", courier, monospace; background-color: #ffffff; \/*white-space: pre;*\/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } <\/style>\n<p>With the body prepared, we just need to call the SPUtility.SendEmail method to send our message.<\/p>\n<pre class=\"csharpcode\">[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$sd,$body)<\/pre>\n<p>If SharePoint accepts the email and sends it onwards, you\u2019ll receive a result of TRUE. Any failure will give a FALSE, or a big red powershell error if something is wrong in the earlier code.<\/p>\n<p><a href=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 5px; display: inline; background-image: none;\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png\" width=\"572\" height=\"40\" \/><\/a><\/p>\n<p>Paul.<\/p>\n<p>&#160;<\/p>\n<p>&#160;<\/p>\n<style type=\"text\/css\">.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, \"Courier New\", courier, monospace; background-color: #ffffff; \/*white-space: pre;*\/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } <\/style>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s quite easy to test SMTP email from your SharePoint site, in fact from any server using the Telnet client and any of the thousands of SMTP test guides across the net. What isn\u2019t so easy is to test outbound email from SharePoint itself and have complete control over what\u2019s being sent. You can of &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[92,33,16,91],"tags":[93],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"It\u2019s quite easy to test SMTP email from your SharePoint site, in fact from any server using the Telnet client and any of the thousands of SMTP test guides across the net. What isn\u2019t so easy is to test outbound email from SharePoint itself and have complete control over what\u2019s being sent. You can of &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-01T14:47:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-12-18T20:08:59+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\",\"name\":\"Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png\",\"datePublished\":\"2012-11-01T14:47:38+00:00\",\"dateModified\":\"2012-12-18T20:08:59+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png\"},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict","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":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/","og_locale":"en_US","og_type":"article","og_title":"Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict","og_description":"It\u2019s quite easy to test SMTP email from your SharePoint site, in fact from any server using the Telnet client and any of the thousands of SMTP test guides across the net. What isn\u2019t so easy is to test outbound email from SharePoint itself and have complete control over what\u2019s being sent. You can of &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2012-11-01T14:47:38+00:00","article_modified_time":"2012-12-18T20:08:59+00:00","og_image":[{"url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png"}],"author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/","name":"Testing SharePoint outbound e-mail - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage"},"image":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage"},"thumbnailUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png","datePublished":"2012-11-01T14:47:38+00:00","dateModified":"2012-12-18T20:08:59+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2012\/11\/testing-sharepoint-outbound-e-mail\/#primaryimage","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/Testing-SharePoint-outbound-e-mail_CC12\/image_thumb.png"},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/527"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=527"}],"version-history":[{"count":2,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/527\/revisions"}],"predecessor-version":[{"id":556,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/527\/revisions\/556"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=527"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}