Send Welcome Email to New User using the Scripting Agent

Hi
I require some assistance please.  I have found a number of scripts online to send a Welcome Email to new users whereby they make use of the ScriptingAgent.xml file.
I like the way the scripts have been configured and have mashed up one or two scripts together for my desired result however when testing in my lab (Exchange 2013) I have found tow problems.
The problems are:
1. When creating a new user and mailbox (New-Mailbox) via the ECP the script throws out an error which I will post later in this post. The mailbox is created fine but it does not send out a welcome email.  When a user is created in ADUC and then a mailbox
is created (Enable-Mailbox) the welcome email is sent out correctly.
2. In the script i have a section to check for NewUser00 in the HTML file and replace that with the Users Name and Surname, however this does not work correctly, I just come up blank:
The Script:
<?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"]
$USRdfirst = $provisioningHandler.UserSpecifiedParameters["FirstName"]
$USRdlast = $provisioningHandler.UserSpecifiedParameters["LastName"]
$UsrAlias = (Get-Mailbox -Filter {SamAccountName -eq $UsrSamAccountName}).Alias.ToString()
$USRdname = $USRdfirst + " " + $USRdlast
# 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()
$USRdfirst=$provisioningHandler.UserSpecifiedParameters["FirstName"]
$USRdlast=$provisioningHandler.UserSpecifiedParameters["LastName"]
$UsrAlias = (Get-Mailbox -Identity $UsrIdentity).Alias.ToString()
$USRdname= $USRdfirst + " " + $USRdlast
# 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 "Contoso.com") {
# HR #
$fromHR="[email protected]"
$SubjectHR="'Welcome to Contoso'"
$BodyHR = [string] (get-content ("c:\welcome\WelcomeMSG.htm"))
$BodyHR = $BodyHR -replace "NewUser00",$USRdname
$fileHR = "c:\welcome\WelcomeMSG.htm"
$smtp="192.168.x.x"
Send-MailMessage -From $fromHR -To $UsrAddr -Subject $SubjectHR -Body $BodyHR -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) -SmtpServer $Smtp
# Clearing variables. Each one in its own line in order to prevent error messages from being shown on EMC.
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 }
</ApiCall>
</Feature>
</Configuration>
The Error for issue 1:
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: You cannot call a method on a
null-valued expression.. ---> System.Management.Automation.RuntimeException:
You cannot call a method on a null-valued expression. at CallSite.Target(Closure , CallSite , Object ) at
System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at
System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame) at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
--- 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)
Any assistance in resolving these two issues will be really appreciated

Ok I am gonna to answer my own question.
I have persevered through the day and have resolved my two issues.  I hope this assist others within the community.
Script:
<?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.
Start-Sleep -s 30
Set-ADServerSettings -ViewEntireForest $true
# New-Mailbox triggered. Taking SamAccountName parameter.
if ($provisioningHandler.UserSpecifiedParameters.Contains("Name") -eq $true) {
$UsrSamAccountName = $provisioningHandler.UserSpecifiedParameters["Name"]
$Usrname = (Get-Mailbox -identity $UsrSamAccountName | Select Name | foreach { $_.Name})
$UsrString = $Usrname | Out-String
$UsrAlias = (Get-Mailbox -Filter {Name -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()
$Usrname = (Get-Mailbox -identity $UsrIdentity | Select Name | foreach { $_.Name})
$UsrString = $Usrname | Out-String
$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 "contoso.com") {
# HR #
$fromHR="[email protected]"
$SubjectHR="'Welcome to CONTOSO'"
$BodyHR = [string] (get-content ("c:\welcome\WelcomeMSG.htm"))
$BodyHR = $BodyHR -replace "NewUser00",$UsrString
$fileHR = "c:\welcome\WelcomeMSG.htm"
$smtp="x.x.x.x"
Send-MailMessage -From $fromHR -To $UsrAddr -Subject $SubjectHR -Body $BodyHR -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) -SmtpServer $Smtp
# Clearing variables. Each one in its own line in order to prevent error messages from being shown on EMC.
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 }
</ApiCall>
</Feature>
</Configuration>

Similar Messages

  • How to send one email to multi-users using JavaMail ?

    I am using JavaMail API. I am working in "sending emails to users", I had already tested "one email to one user" and got success but when tried to send one email to multi-users then I failed to do that?
    Can anyone help me to do this?
    I have used the below code to send to multi-user:
    Address[] toAddr = {new InternetAddress(_to),new InternetAddress (to2)};
    msg.addRecipients(Message.RecipientType.TO, toAddr);
    But it is static only 2 users. I want to send to multi-users dynamically taking datas from database.
    I have tried by using below code but it doesn't work.....
    InternetAddress[] emails;
    while (resultset.next()) {
    temp = resultset.getString(1);
    emails.setAddress(temp);
    i++;
    Address[] toAddr = emails;
    msg.addRecipients(Message.RecipientType.TO, toAddr);
    Thank you in advance...
    -ritesh

    I think you're confused about some basic Java programming techniques.
    There are two obvious ways to do this.
    1. Call the addRecipient method in a loop.
    2. Collect all the recipients in a List, convert it to an array, and call addRecipients.

  • How to send HTML email to End User using OOTB email processs?

    Hi,
    We are using OOTB Send email process to send email to end user.
    Templates has been created inside /etc/workflow/ProjectName/email folder.
    Its working properly for plain text email.but for html template ,It send the email with html tags.
    Any pointer on how to write html template for OOTB email process and activate email type as html ?
    Thanks
    Deepika

    Thanks Sham..
    I am able to send HTML email following above link.
    The problem i am facing is,When i am deploying the code through crxde.Code is working fine.
    But using maven deploy..Bundle get activated ..But at line:
    messageGateway = this.messageGatewayService.getGateway(HtmlEmail.class);
    ,it gives null Pointer exception.
    Any pointer,why its not working from maven deployment.
    Regards
    Deepika

  • How to send email to external users using the distribution list from workflow

    I have created distribution list in SO23 with external email addresses.
    How I can use distribution list in "Send Mail component" or I should use another component?
    It works fine for a single email address. And distribution list works fine when I use it via SBWP.

    Hi,
      Take activity step instead of Mail step. User fm SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail.
    And use fm SO_DLI_READ_API1 to find list of user from    distribution list. You can    find how to use this fm in rule 30000012

  • Every time i send an email my new ipad adds the email address to contacts

    Looking for a setting that must turn this off. I replied to an email in Outlook on my PC and it took their email address, synced it to my iPad and added that email address to my ipad contacts. Help! I'll never need this person's info again. My contacts are multiplying...

    there is no setting on the pad that will help with this.
    There may be a setting in outlook on your pc.  That is where the action of adding the contact is happening.  (I just looked at my outlook, and cannot find a way to stop that from happening. It may be there , I just cannot find it).
    You can delete individual contacts from the contact app.

  • Custom welcome email to new wiki members.

    Hi, any know how custom welcome email to new wiki members?
    I need change the language to Catalan and image to university logo.
    Any method?
    Thanks a lot!

    Hi,
    Based on my knowledge, Exchange doesn't have built-in function to send welcome emails to new mailboxes by department. For more information, actually, we have a dedicated support team regarding the Microsoft Exchange Development. I recommend you ask your
    question on our Exchange Development forum which is staffed by more experts specializing in this kind of problems. Thanks for your understanding.
    For your convenience:
    http://social.technet.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment
    Hope it helps.
    Best regards,
    Amy Wang
    TechNet Community Support

  • Welcome email to new mailbox created by department

    Hi,
    We have 4 different welcome messages because we have 1 exchange server for all locations.
    Each location we need to change the welcome message. Is this possible? Pls adv. Thanks.
    Warm Regards,
    Josette

    Hi,
    Based on my knowledge, Exchange doesn't have built-in function to send welcome emails to new mailboxes by department. For more information, actually, we have a dedicated support team regarding the Microsoft Exchange Development. I recommend you ask your
    question on our Exchange Development forum which is staffed by more experts specializing in this kind of problems. Thanks for your understanding.
    For your convenience:
    http://social.technet.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment
    Hope it helps.
    Best regards,
    Amy Wang
    TechNet Community Support

  • The problem is with the new operating system  and sending photo via email when used in my iPad.   From photo I selected 3 photos to send via email. I choose the upload key and choose to send by email. Typing text on the email is very slow.

    The problem is with the new operating system  and sending photo via email when used in my iPad.
    From photo I selected 3 photos to send via email. I choose the upload key and choose to send by email. Typing text on the email is very slow. This is solved by saving the email as a draft and opening the email again from mail.
    Can you amend he system to allow emails to be sent from photo as previously.

    Have you tried restarting or resetting your iPad?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after the iPad shuts down, then press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10 seconds). Ignore the "Slide to power off"

  • Sending email to user using the notification template in OIM 11g

    Hi all
    I have created a Notification Template using web console in OIM 11g.
    Iam able to access the contents from notification template in my java code.
    But iam not able to find the correct api's to send email to user using the notification template
    (like tcEmailNotificationUtil using this class we can connect to email template created in design console and creating IT resourse we can send email to user using the method sendEmail).
    Waiting for your help and pointers
    Thanks and Regards
    Bipin patil

    Thanks GP!.
    But i have the same doubt here.
    "The Notification Event is defined through a XML file that must be loaded into MDS database." - in which path and in what name it should be.
    Because under /metadata/iam-features-notification, i couldnt see any event Xml present. I thought atleast we could see the existing OOB notification template's event xml files.
    Please let me know if you are aware.
    Thanks,
    Amudha

  • Send email to external user using fm 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    Hi friends,
    I wrote this code to send mail to external user from sap.
    It did not work properly can anyone help me to send email to extenal user.
    The return code after executing the function module is 2.
    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS  2 WITH HEADER LINE.
    DATA: OBJHEAD LIKE SOLISTI1   OCCURS  1 WITH HEADER LINE.
    DATA: OBJBIN  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE.
    DATA: OBJTXT  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE.
    DATA: RECLIST LIKE SOMLRECI1  OCCURS  5 WITH HEADER LINE.
    DATA: DOC_CHNG LIKE SODOCCHGI1.
    DATA: TAB_LINES LIKE SY-TABIX.
    Creating the document to be sent
    DOC_CHNG-OBJ_NAME = 'OFFER'.
    DOC_CHNG-OBJ_DESCR = 'abcd'.
    OBJTXT = 'aaaaaaaaaaa:'.
    APPEND OBJTXT.
    OBJTXT = 'bbbbbbbbbb'.
    APPEND OBJTXT.
    OBJTXT = 'ccccccccccccc.'.
    APPEND OBJTXT.
    DESCRIBE TABLE OBJTXT LINES TAB_LINES.
    READ TABLE OBJTXT INDEX TAB_LINES.
    DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    RECLIST-RECEIVER = mail address.
    RECLIST-REC_TYPE = 'U'.
    RECLIST-COM_TYPE = 'INT'.
    RECLIST-NOTIF_DEL = 'X'.
    RECLIST-NOIF_NDEL = 'X'.
    APPEND RECLIST.
    Creating the entry for the compressed document
    CLEAR OBJPACK-TRANSF_BIN.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM   = 0.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM   = TAB_LINES.
    OBJPACK-DOC_TYPE   = 'RAW'.
    APPEND OBJPACK.
    Creating the document attachment
    (Assume the data in OBJBIN are given in BMP format)
    OBJBIN = ' \O/ '. APPEND OBJBIN.
    OBJBIN = '     '. APPEND OBJBIN.
    OBJBIN = ' / \ '. APPEND OBJBIN.
    DESCRIBE TABLE OBJBIN LINES TAB_LINES.
    OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.
    Creating the entry for the compressed attachment
    OBJPACK-TRANSF_BIN = 'X'.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM   = 1.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM   = TAB_LINES.
    OBJPACK-DOC_TYPE   = 'BMP'.
    OBJPACK-OBJ_NAME   = 'ATTACHMENT'.
    OBJPACK-OBJ_DESCR = 'Reproduction object 138'.
    OBJPACK-DOC_SIZE   = TAB_LINES * 255.
      APPEND OBJPACK..
    Sending the document
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
              DOCUMENT_DATA = DOC_CHNG
              PUT_IN_OUTBOX = 'X'
              COMMIT_WORK   = 'X'
         TABLES
              PACKING_LIST  = OBJPACK
              OBJECT_HEADER = OBJHEAD
             CONTENTS_BIN  = OBJBIN
               CONTENTS_TXT  = OBJTXT
               RECEIVERS     = RECLIST
          EXCEPTIONS
               TOO_MANY_RECEIVERS = 1
               DOCUMENT_NOT_SENT  = 2
               OPERATION_NO_AUTHORIZATION = 4
               OTHERS = 99.
    IF SY-SUBRC NE 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Hi,
    Check in SCOT t-code whether it has been properly configred to send the mails
    Regards,
    siva chalasani.

  • I set up my new computer using the apple ID i always use, and then later migrated all my files from my old mac book to the same new one, but under a different user (same ID). how do i consolidate the two users on my new mac book?

    i set up my new computer using the apple ID i always use, and then later migrated all my files from my old mac book to the same new one, but under a different user (same apple ID). how do i consolidate the two users on my new mac book?

    Well if you use the Finder Go menu to Computer, a window opens up double click on your boot drive and then on Users folder, open the other user folder and open Public and drop your files into DropBox
    When you do this it will copy them and change the permissions and user assigned to it, so log into the other user and place them into your respective normal folders.
    Once you have all your files over and don't need the old user, use System Preferences > Accounts to delete it if you wish, however it's good two Admin accounts on the machine in case something bad happens in the other. Some people for security reasons on use a Standard account for most uses and a emergency Admin account.
    One can still do most Admin things in Standard user.

  • Yesterday I changed my email password on my home computer.  Today, I can't get any new emails on my Samsung Galaxy 4; I deleted the email account entirely and tried to set it up again as a new account, using the new password, but it keeps giving me an err

    Yesterday I changed my email password on my home computer.  Today, I can't get any new emails on my Samsung Galaxy 4; I deleted the email account entirely and tried to set it up again as a new account, using the new password, but it keeps giving me an error message that reads: Cannot safely connect to server.  The new password is working on my home computer.  I even tried the old password; it just gave me the same error message.

    I'm sorry you're having issues with your e-mail account on your phone Rusty1112. Let's figure out what's going on. First, please try deleting account/information again and then restart phone. When phone is back on, try adding e-mail account again, and be sure you're entering exactly as you set up, meaning its case-sensitive. If you're still getting same error, please let us know and let us know what e-mail account it is, Yahoo, AOL, MSN, etc.
    Thank you,
    VanessaS_VZW
    Follow us on Twitter @VZWSupport

  • When I send an email it shows up in the sent folder as new, how do I fix this so it shows it as read automatically?

    When I send an email it shows up in the sent folder as new, how do I fix this so it shows it as read automatically?

    I don't want all my mail to be marked as read, just the sent messages. I set Thunderbird up on my new PC and whenever I send an email it goes to my sent folder like I want, but it shows up as a new or unread message. I have Thunderbird on my two other PC's and it doesn't act this way. On the other PC's when I send out an email, it shows up in my sent folder as read. That's the way I want it to act on my new PC. With the other two PC's I didn't have to do anything to the setting it was like that from the start.
    I appreciate any help I can get in this matter. Thank you

  • How can I send an email from Sharepoint Online using sandbox solution?

    How can I send an email from Sharepoint Online using sandbox solution?
    If possible I do not want to use workflow.
    Is It possible to do it without using workflow?

    hello Steven Andrews,
    when any user sends a message using contact us page in SharePoint online.
    1. We are inserting item in Contact Us List . - This is working fine
    for anonymous users also. We have used Office365 anonymous codeplex wsp and it is working fine. Anonymous user is able to insert new record in the Contact Us List.
    2. Once, new record is inserted in Contact Us list, we want to fire email notifying thanks to the user on his email id as well as to our company x person for notification of new inquiry. 
    We tried using Workflow having impersonation step for  anonymous user but it is not working for Anonymous users. Workflow is able to sent the email if someone logged into system but not working for Anonymous user although workflow is getting started
    but not able to send email although used Imperonsation step.
    We are stuck into implementing second step.

  • Create and send an email as a delegate using EWS Managed API

    Hi All,
    I would like to create and send an email as a delegate using EWS Managed API for that i have crated one user as a delegate to that mailbox owner.
    after adding user as delegate, when i try to create an email The EmailMessage class taking only FolderId as parameter but not taking Mailbox object as parameter. But in web reference they said that EmailMessage taking FolderId and Mailbox object as parameter.
    EmailMessage message = new EmailMessage(service);
    message.Subject = "Company Soccer Team";
    message.Body = "Are you interested in joining?";
    message.ToRecipients.Add("[email protected]");
    message.Save(new FolderId(WellKnownFolderName.Drafts, new Mailbox("[email protected]")));https://msdn.microsoft.com/EN-US/library/office/dn641963(v=exchg.150).aspx#bk_createewsmacould you people please help me on this?ThanksNaresh

    Thanks for reply glen.
    I have added delegate using Add-MailboxPermissions. Now i am able to save an email in mailbox owner drafts
    folder.
    Glen,
     I have a one more question.(I am using EWS Managed API).
    I(owner) have shared my calendar(eg. samplecalenderfolder) with another user(delegate) (i.e.,he is the
    delegate of my mailbox) and i have given only permission to the this folder(samplecalenderfolder)
    only and the permission level is Reviewer.
    if i login with user(i.e.delegate) i am not able to get the shared calendar folders(i.e.,samplecalenderfolder)
    that what i a have shared.
    below is the code snippet i am using to get the calendar folders.
    Folder folder = Folder.Bind(service,WellKnownFolderName.Calendar);
    FindFoldersResults addtionalFolders = service.FindFolders(folder.Id, new FolderView(10));
    could you please tell us how to get the shared calendar folders.
    Thanks
    Naresh

Maybe you are looking for

  • Can not activate master data

    Hey, on the employee characteristic i have activated the master data, but when i check the "Q-" table there are still record whith "M" ?? The activate tell me that there are nothing to activate. Is there anyone who can tell me, how i active the data.

  • How to access request information in a webservice implementation (10.1.3)

    Hi, I have created a java webservice from WSDL in JDeveloper 10.1.3.4. In the Impl class I would like to access HTTP request information. Can I do this in a direct way? If not, I have made a custom javax.xml.rpc.handler.Handler (by extending GenericH

  • Attachments not sending on email from Pre

    Hi: Since implementing the most recent update, I can not send attachments from my Pre (whether using my POP, GMAIL, or HOTMAIL accounts. The emails go through but the attachment is lost. Is anyone else having this problem and, if so, have you found a

  • N80 & Orange packet data

    I wonder if anyone else has had the same experience as I've had, I was just playing with my Orange N80 and when I looked in the log file I found the data counter had registered all sent data as 3.05MB and all received data as 4.72MB and all I'd done

  • Sales order with special procurement

    Hi, We are having a problem raising a sales order were the material has a special procurement marker as there is a clash between this and the Item category we have to enter on a sales order. We get our products manufactured by an outside supplier. To