Since Exchange 2010, it has been possible to use Scripting Agents to perform additional checks/processing when certain cmdlets are run. This feature can be used to automatically send an email to welcome new users. An overview of scripting agents and how they work can be found on Technet.
To send an email when a new mailbox is created, we need to respond to New-Mailbox or Enable-Mailbox (New-Mailbox is used when there is no existing AD account, and Enable-Mailbox is used when an existing AD user is mail-enabled). Attached you'll find a sample Scripting Agent that will respond to both cmdlets, obtain the related mailbox/AD object, and use this information to send a personalised welcome email to the new mail user.
To create the personalised message, the easiest way is to write it using Outlook, then save as HTML. In the sample agent, I've included code that will replace any occurrence of #UserFirstName# in the welcome message with the actual first name of the user (as read from Active Directory). This can be extended as needed to include other fields. If you have any images in the message, then there are some additional steps to take. When the message is saved, you'll find the html file, and then a folder of the same name containing any images (and a few other files, most likely, but these we can ignore). Both the script and the welcome message need to be modified to be able to send these images. The steps are as follows:
In the script, go to the part commented "Add any linked resource (e.g. images)". In the sample script, you'll just find one image (the Microsoft logo, of course!). For each image, you need to load it as a linked resource and add it to the list. To make editing the HTML file simpler, set the ContentId to the filename (no path, just the filename). The ContentType needs to be set to the correct MIME type for the image (e.g. image/jpeg, image/png, etc.). The image needs to be available to the Exchange server at the given path when it is loaded - so it is usually best to put it on the machine somewhere. For every image, you'll have four lines in the script to load it into the message:
$image = New-Object System.Net.Mail.LinkedResource("C:\WelcomeMessage\image001.png") $image.ContentId = "image001.png" $image.ContentType = "image/png" $view.LinkedResources.Add($image) The above lines add the image as an attachment to the message, and define it as a linked resource with a specific ContentId. The next step is to update the message HTML so that the image references point to the correct attachment (which is done by referencing the ContentId of the image). So, you need to open the html file in your favourite text editor (Notepad is fine for this, though Notepad++ adds syntax highlighting which makes the HTML much easier to follow). When it is open, do the following for each image in the document:
Now the HTML is updated, all you need to do it copy it and the images to the folder specified in the scripting agent (for this example, I copied all the files to c:\WelcomeMessage - note that this needs to be present on each Exchange server that the agent is deployed on). The welcome message preparation is then complete.
Additional scripting agent code needs to be updated to work with your environment. The things you'll need to check are SMTP server (the script using System.Net.Mail, so sends the message using SMTP), from address, and message subject. Once these changes have been made, the ScriptingAgentConfig.xml needs to be placed on each Exchange server in the folder C:\Program Files\Microsoft\Exchange Server\V14\Bin\CmdletExtensionAgents (assuming default Exchange installation). If there is already one there, you'll need to combine the scripts.