Pankaj,
The to field is fetched dynamically from the commtemplate as part of the sendMessage method. Specifically it takes the target Mbo, which in your case is the comm template itself and then resolves the send to based on the COMMTMPLT_TO relationship from the template to the COMMTMPLTSENDTO table. From there it finds the role, person or email to send the email to and uses that.
Assuming you want to send only to a specific user you could use temporarily add a record to the COMMTMPLTSENDTO object by the COMMTMPLT_TO relationship.
So something like this:
def send_email(email_to,email_from,email_subject,email_body):
ctSet=MXServer.getMXServer().getMboSet("COMMTEMPLATE", mbo.getUserInfo())
strWhere="templateid='LBL_GENERIC_EMAIL'"
ctSet.setWhere(strWhere)
ctSet.reset()
if (not ctSet.isEmpty()):
ctMbo=ctSet.getMbo(0)
ctMbo.setValue("subject", email_subject, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctMbo.setValue("sendfrom",email_from , MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctMbo.setValue("message", email_body, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctTOSet = ctMbo.getMboSet("COMMTMPLT_TO")
toemail = ctTOSet.add()
toemail.setValue("TYPE", "EMAIL")
toemail.setValue("SENDTO", True)
toemail.setValue("SENDTOVALUE", email_to)
# Do not save since we just want it to be temporary
try: # since it could be a blocking call
ctMbo.sendMessage(ctMbo, ctMbo)
except:
pass
ctTOSet=None
ctSet=None
Note that you should close the MboSet not just set them to None and that should be in a finally block like this so that the MboSet is closed everytime.
def send_email(email_to,email_from,email_subject,email_body):
ctSet=MXServer.getMXServer().getMboSet("COMMTEMPLATE", mbo.getUserInfo())
try:
strWhere="templateid='LBL_GENERIC_EMAIL'"
ctSet.setWhere(strWhere)
ctSet.reset()
if (not ctSet.isEmpty()):
ctMbo=ctSet.getMbo(0)
ctMbo.setValue("subject", email_subject, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctMbo.setValue("sendfrom",email_from , MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctMbo.setValue("message", email_body, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
ctTOSet=ctMbo.getMboSet("COMMTMPLT_TO")
toemail = ctTOSet.add()
toemail.setValue("TYPE", "EMAIL")
toemail.setValue("SENDTO", True)
toemail.setValue("SENDTOVALUE", email_to)
# Do not save since we just want it to be temporary
try: # since it could be a blocking call
ctMbo.sendMessage(ctMbo, ctMbo)
except:
pass
finally:
if not ctSet is None:
ctSet.close()
ctSet=None
Also you have a comment about using a try / catch because the call may be blocking. Be aware that a try / catch is not going to stop the blocking call, you would need to create a new thread if that is the intent.
Jason
Jason VenHuizen +1-206-669-6430 | sharptree.io |