我无法弄清楚如何在服务器级别创建邮件会话。
这是我的调用脚本:
WasLib.createMailSession("MY_MAIL_SESSION","mail/Emailer","smtp-myserver.com", "", "", "")
此脚本现有脚本在单元级别创建邮件会话,但我需要将范围更改为服务器级别。到目前为止,每次运行脚本时,我都被迫手动重新创建邮件会话。
这是我的WasLib.createMailSession函数:
def createMailSession(sessionName, jndiName, mailTransportHost, mailTransportUser, mailTransportPassword, mailFrom):
print 'Creation du Mail Session : ' + sessionName
name = ['name', sessionName ]
jndi = ['jndiName', jndiName ]
host = ['mailTransportHost', mailTransportHost ]
user = ['mailTransportUser', mailTransportUser ]
password = ['mailTransportPassword', mailTransportPassword ]
mFrom = ['mailFrom', mailFrom ]
protocol = ['mailTransportProtocol', getProtocolProvider('smtp') ]
debug = ['debug', "true" ]
strict = ['strict', "true" ]
mailAttrs = [ name, jndi, host, user, password, mFrom, protocol, debug, strict ]
#print "attributes" + AdminConfig.attributes('MailSession')
#print "Required " + AdminConfig.required('MailSession')
mailSession = AdminConfig.create('MailSession', **getMailProvider()**, mailAttrs)
if (mailTransportUser != "") :
for itemId in AdminConfig.list('J2EEResourcePropertySet', mailSession).split(lineSeparator) :
if len(itemId) == 0 :
itemId = AdminConfig.create('J2EEResourcePropertySet', mailSession, "[]")
AdminConfig.create('J2EEResourceProperty', itemId, '[[name "mail.smtp.port"] [type "java.lang.String"] [description ""] [value "587"] [required "false"]]')
AdminConfig.create('J2EEResourceProperty', itemId, '[[name "mail.smtp.auth"] [type "java.lang.String"] [description ""] [value "true"] [required "false"]]')
AdminConfig.create('J2EEResourceProperty', itemId, '[[name "mail.smtp.from"] [type "java.lang.String"] [description ""] [value "' + mailFrom + '"] [required "false"]]')
#endIf
#endFor
#endIf
return mailSession
#endDef
正如您所看到的,getMailProvider返回单元格,当我将其更改为服务器时,它会失败。
def getMailProvider():
return AdminConfig.getid('/Cell:'+AdminControl.getCell()+'/MailProvider:Built-in Mail Provider/')
#endDef
我试过这个没有运气:
def getMailProvider():
return AdminConfig.getid('/Cell:'+ AdminControl.getCell()
+'/Node:'+ AdminControl.getNode() +'/Server:'+ getServer() +'/')
#endDef
答案 0 :(得分:1)
您在第二个示例中缺少+'/MailProvider:Built-in Mail Provider/'
。
完整的命令应该是:
AdminConfig.getid('/Cell:' + AdminControl.getCell() + '/Node:' + AdminControl.getNode() + '/Server:server1' + '/MailProvider:Built-in Mail Provider/')