Welcome E-Mail to Exchange 2013 Users RRS feed

  • Question

  • Hi

    We have Exchange 2013 SP1 environment and we have enabled "Scripting Agents" for sending Welcome E-Mail to all users whose Mailbox will be enabled. Its working fine for "New-Mailbox" cmdlets but its not working for "Enable-Mailbox". We are getting following error while enabling mailbox for existing AD user:

    The cmdlet extension agent with the index 5 has thrown an exception in OnComplete(). The exception is: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Exception thrown while invoking scriptlet for OnComplete API: A recipient must be specified.. ---> System.InvalidOperationException: A recipient must be specified. at System.Net.Mail.SmtpClient.Send(MailMessage message) at Microsoft.PowerShell.Commands.SendMailMessage.EndProcessing() --- End of inner exception stack trace --- at Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e) at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnCompleteImpl(Task task, Boolean succeeded, Exception exception)

    Below is the ScriptingAgentConfig.xml file used for sending Welcome E-Mail:

    <?xml version="1.0" encoding="utf-8" ?>

    <Configuration version="1.0">

       <Feature Name="MailboxProvisioning" Cmdlets="New-Mailbox,Enable-Mailbox">

         <ApiCall Name="OnComplete">

           If($succeeded) {

             $mbx = $provisioningHandler.UserSpecifiedParameters["Name"]

             Set-Mailbox $mbx -SingleItemRecoveryEnabled $True



    <Feature Name="Welcome E-Mail" Cmdlets="New-Mailbox,Enable-Mailbox">

         <ApiCall Name="OnComplete">

           If($succeeded) {

     $DisplayName = $provisioningHandler.UserSpecifiedParameters["DisplayName"]

     $emailAddress = $mbx + ""

     $emailMsg = [String] (Get-Content ("C:\Welcome\WelcomeMSG.htm"))

     $emailMsg = $emailMsg -Replace "UserName", $DisplayName

     Send-MailMessage -From "" -To $emailAddress -SMTPserver "" -Subject "Welcome!" -Body $emailMsg -BodyAsHTML




    Please help me out so sending Welcome E-mail to Exchange 2013 users.



    Wednesday, April 2, 2014 6:07 PM

All replies

  • The main problem you are facing is that user mailbox can be created using two cmdlets: new-mailbox and enable-mailbox. First one works well, but when you try to do the same scripting with Enable-Mailbox cmdlet, everything fails.

    Go through the following and just use this script, it should work fine:

    Basic steps to configure welcome message on Exchange 2013 server:

    1. Place the following script on every Exchange server in your Exchange organization (except Transport server role i.e. Mailbox Server in case of Exchange 2013) into the following folder: «C:\Program Files\Microsoft\Exchange Server\V15\Bin\CmdletExtensionAgents\ScriptingAgentConfig.xml».
      Please be attentive to not start step 2 before working version of the script is in the folder.

    <?xml version="1.0" encoding="utf-8" ?>

    <Configuration version="1.0">

    <Feature Name="WelcomeEmail" Cmdlets="New-Mailbox,Enable-Mailbox">

    <ApiCall Name="OnComplete">

    if($succeeded) {

    # Waiting for synchronization after mailbox has been created.

    Set-ADServerSettings -ViewEntireForest $true

    Start-Sleep -s 10

    # New-Mailbox triggered. Taking SamAccountName parameter.

    if ($provisioningHandler.UserSpecifiedParameters.Contains("SamAccountName") -eq $true) {

    $UsrSamAccountName = $provisioningHandler.UserSpecifiedParameters["SamAccountName"]

    $UsrAlias = (Get-Mailbox -Filter {SamAccountName -eq $UsrSamAccountName}).Alias.ToString()


    # Enable-Mailbox triggered. Taking Identity parameter, this is the only one avalaible in this case.

    if ($provisioningHandler.UserSpecifiedParameters.Contains("Identity") -eq $true) {

    $UsrIdentity = $provisioningHandler.UserSpecifiedParameters["Identity"].ToString()

    $UsrAlias = (Get-Mailbox -Identity $UsrIdentity).Alias.ToString()


    # Defining variables.

    $UsrAddr = (Get-Mailbox -Filter {Alias -eq $UsrAlias}).PrimarySmtpAddress.ToString()

    $UsrOU = (Get-Mailbox -Filter {Alias -eq $UsrAlias}).OrganizationalUnit

    # Sending email notification to the user in specific OU.

    if ($UsrOU -match "DOMAIN.LOCAL/OrganizationalUnit") {

    $UsrMsg = [string](Get-Content ("c:\scripts\WelcomeMessage.html"))

    Send-MailMessage -SmtpServer "MAILER.DOMAIN.LOCAL" -To "$UsrAddr" -From "welcome@DOMAIN.LOCAL" -Subject "Welcome to our company!" -Body $UsrMsg -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)


    # Clearing variables. Each one in its own line in order to prevent error messages from being shown.

    if ($UsrAlias) { Remove-Variable UsrAlias }

    if ($UsrAddr) { Remove-Variable UsrAddr }

    if ($UsrOU) { Remove-Variable UsrOU }

    if ($UsrMsg) { Remove-Variable UsrMsg }

    if ($UsrIdentity) { Remove-Variable UsrIdentity }

    if ($UsrSamAccountName) { Remove-Variable UsrSamAccountName }





    This script assumes that welcome message body is placed in «c:\scripts\WelcomeMessage.html» on every Mailbox (Hub Transport) server. Don’t forget to edit parameters marked with red.

    2. Enable Scriptng Agent extension on the Exchange infrastructure.

    Enable-CmdletExtensionAgent "Scripting Agent"

    3. Restart every Exchange Control Panel that already runs.

    4. Try to create/enable a new mailbox user. This should do the trick.

    Tuesday, April 8, 2014 8:42 AM