«

»

Nov 01

Testing SharePoint outbound e-mail

It’s 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’t so easy is to test outbound email from SharePoint itself and have complete control over what’s being sent. You can of course configure an alert, and hope that this will send an e-mail, but you don’t have complete control of the process as you are reliant on timer jobs and other variables to process that alert.

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’re going to use PowerShell. (This is the original blog post.)

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.

Firstly we use a String dictionary to create the header collection, and then add the various header nodes to it.

$sd = new-object System.collections.specialized.stringdictionary
$sd.add("to","ourrecipient@email.address")
$sd.add("from","outsender@email.address")
$sd.add("Subject","The clue is in the name!")

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.

$web = get-spweb "http://www.myfatblog.co.uk"
$body = "This is our body<br/> We can use <strong>HTML</strong> codes in it."

With the body prepared, we just need to call the SPUtility.SendEmail method to send our message.

[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$sd,$body)

If SharePoint accepts the email and sends it onwards, you’ll 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.

image

Paul.

 

 

2 comments

1 ping

  1. Anthony

    Works! Thanks!

  2. tristian

    nice one… works well

  1. Testing Sharepoint outbound email via PowerShell | Sharepoint Inquest

    […] Original post: http://www.myfatblog.co.uk/index.php/2012/11/testing-sharepoint-outbound-e-mail/ […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.