Thursday, 30 May 2024

Send Email from Automation Script, Multiple ways | Maximo

 1. Here’s a simple, famous 3-line code snippet to send an email. This example uses a communication template, but the body (MESSAGE) can be dynamically modified as needed

    ctMboSet = mbo.getMboSet("$commtemp","COMMTEMPLATE"," TEMPLATEID ='COE_SCHEDULED' ");

    ctMboSet.setQbeExactMatch("true")      

    ctMboSet.reset()

    ctMbo = ctMboSet.getMbo(0)

    ctMbo.setValue("MESSAGE", txtres)

    if(ctMbo is not None):

        ctMbo.sendMessage(mbo,mbo);

2.  In many communication systems, there is a need to dynamically add multiple recipients. This can be done by using a method called Create Communication where recipients are added as a comma-separated string. Below is an outline and code examples to help you understand and implement this functionality. 

    clMbo = mbo.createComm()

    clMbo.setValue("TEMPLATEID", "COE_SCHEDULED")

    clMbo.setValue("SENDTO", vEmailaddresses)

    clMbo.sendMessage()


An example of generating a comma-separated Python list, which is used in the previous Example 2, is provided below

    vAttendeeSet = mbo.getMboSet("COE_COURSE_LINE")

    eList = []

    for i in range ( 0, vAttendeeSet.count()):

        vViewLine = vAttendeeSet.getMbo(i)

        email= vViewLine.getString("PERSON.PRIMARYEMAIL") 

        eList.append(email)

    vEmailaddresses = ",".join(list(set(eList)))    

No comments:

Post a Comment