AD 脚本kixtart运用之六(outlook邮件批量生成签名)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AD 脚本kixtart运用之六(outlook邮件批量生成签名)相关的知识,希望对你有一定的参考价值。
基于上一编文章http://windyma.blog.51cto.com/661702/1967071里的设置
我们在Function.kix添加如下内容(备注:此outlook签名function来自网上,经过我比较大的修改):
----------------
Function GenerateOutlookSig($SignatureFileName)
$EmailAccountName = @WUSERID
;----获取outlook配置profile名字(如果有多个profile名字的话,只会取第一个)
If KeyExist("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles")
$ENUMKEY = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
Endif
If KeyExist("HKCU\Software\Microsoft\Office\15.0\Outlook\Profiles")
$ENUMKEY = "HKCU\Software\Microsoft\Office\15.0\Outlook\Profiles"
EndIf
$ProfileName = ENUMKEY("$ENUMKEY", 0)
$ENUMKEY = "$ENUMKEY\$ProfileName\9375CFF0413111d3B88A00104B2A6676"
$hexEmailAccountName = OutlookHexConvert($EmailAccountName)
$hexSignatureFileName = OutlookHexConvert($SignatureFileName)
$KeyNumber = "00000001"
While $KeyNumber <> "" and $MatchFound <> True
$KeyNumber = ENUMKEY("$ENUMKEY", $Index)
$subIndex = 0
While @ERROR = 0 and $subMatchFound <> True
$ValueName=ENUMVALUE("$ENUMKEY\$KeyNumber", $subIndex)
If $ValueName = "New Signature"
$subMatchFound = True
EndIf
$subIndex = $subIndex +1
Loop
If $subMatchFound = "True"
$MatchFound = True
EndIf
$Index = $Index + 1
Loop
If $KeyNumber = ""
LogEvent(1, 0, "Email account $EmailAccountName was not found for user @WUSERID. Aborting signature update.", , "KiXtart")
$GenerateOutlookSig = False
Exit
EndIf
;----从域系统获取用户信息
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.givenName + " " + $objUser.sn
$strJob = $objUser.title
$strEmail = $objUser.mail
$strMobile = $objUser.mobile
If $strCompany = "" $strCompany = $objUser.company EndIf
If $strPhone = "" $strPhone = $objUser.telephoneNumber EndIf
If $strFax = "" $strFax = $objUser.facsimiletelephonenumber EndIf
If $strWebsite = "" $strWebsite = $objUser.wWWHomePage EndIf
;----生成签名html文件的内容
$HTMLdata=‘<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><META content="text/html; charset=gb2312" http-equiv=Content-Type>‘
$HTMLdata=$HTMLdata + ‘<META name=GENERATOR content="MSHTML 11.00.10570.1001"></HEAD><BODY><DIV><FONT size=2 face=Arial><STRONG>Kind regards,</STRONG> <BR><BR></FONT>‘
$HTMLdata=$HTMLdata + ‘<TABLE style="HEIGHT: 167px; WIDTH: 460px; MARGIN-TOP: 0px" cellSpacing=0 cellPadding=0 width=460 border=0>‘
$HTMLdata=$HTMLdata + ‘<TR><TD style="PADDING-BOTTOM: 5px; PADDING-RIGHT: 5px" vAlign=top width=85 noWrap align=left><FONT size=2 face=Arial>‘
$HTMLdata=$HTMLdata + ‘<IMG style="HEIGHT: 80px; WIDTH: 80px" border=0 hspace=0 src="http://www.neo-concept.com.cn/mail-logo.jpg" width=80 align=baseline height=80></FONT>‘
$HTMLdata=$HTMLdata + ‘</TD><TD vAlign=top noWrap align=left><FONT color=#000000 size=2 face="Trebuchet MS">‘ + $strName + ‘<BR><STRONG>‘ + $strCompany + ‘</STRONG>‘
$HTMLdata=$HTMLdata + ‘<BR>Tel: ‘ + $strPhone + ‘<BR>Fax: ‘+ $strFax
if $strMobile <> "" $HTMLdata=$HTMLdata + ‘<BR>Mobile: ‘+ $strMobile ENDIF
$HTMLdata=$HTMLdata + ‘<BR>Internet: <A style="TEXT-DECORATION: none" href="‘ + $strWebsite + ‘" ><FONT color=#000000 >‘+ $strWebsite + ‘</FONT></A></FONT></TD></TR><TR>‘
$HTMLdata=$HTMLdata + ‘<TD vAlign=top colSpan=2 noWrap align=left><HR color=#ffcc00 SIZE=1 style="HEIGHT: 1px; WIDTH: 460px">‘
$HTMLdata=$HTMLdata + ‘<FONT color=#000000 size=1 face="Trebuchet MS">The content of this e-mail is intended solely for the use of the Individual or entity to whom it is<BR>‘
$HTMLdata=$HTMLdata + ‘addressed. If you have received this communication in error, be aware that forwarding it,copying<BR>it, or in any way disclosing its content to any other person, ‘
$HTMLdata=$HTMLdata + ‘is strictly prohibited. If you have<BR>received this communication in error, please notify the author by replying to this e-mail immediately.</FONT></TD></TR></TABLE></DIV></BODY></HTML>‘
;----生成签名HTML文件(先将删除旧的同名文件)
$ffh=FreeFileHandle()
If NOT Exist("%appdata%\Microsoft\Signatures") MD "%appdata%\Microsoft\Signatures" EndIf
If Exist("%appdata%\Microsoft\Signatures\$SignatureFileName.htm") Del "%appdata%\Microsoft\Signatures\$SignatureFileName.htm" EndIf
If @ERROR = 0
$htmlFile=open($ffh,"%appdata%\Microsoft\Signatures\$SignatureFileName.htm",5)
$htmlFile=writeline($ffh,$HTMLdata)
$htmlFile=close($ffh)
Else
$SigGenFailed = True
EndIf
;---生成签名text文件的内容
$PLAINdata=‘Kind regards,‘[email protected]
$PLAINdata=$PLAINdata+‘Tel: ‘ + [email protected]
$PLAINdata=$PLAINdata+‘Fax: ‘+ [email protected]
if $strMobile $PLAINdata=$PLAINdata+‘Mobile: ‘ + $strMobile [email protected] ENDIF
$PLAINdata=$PLAINdata+‘Internet: ‘ + $strWebsite [email protected][email protected]
If $strDisclaimer
$strDisclaimerExpanded = Split($strDisclaimer, "<br>")
For Each $line in $strDisclaimerExpanded
Next
EndIf
;----生成签名text文件(先将删除旧的同名文件)
$ffh=FreeFileHandle()
If Exist("%appdata%\Microsoft\Signatures\$SignatureFileName.txt") Del "%appdata%\Microsoft\Signatures\$SignatureFileName.txt" EndIf
If @ERROR = 0
$plainFile=open($ffh,"%appdata%\Microsoft\Signatures\$SignatureFileName.txt",5)
$plainFile=writeline($ffh,$PLAINdata)
$plainFile=close($ffh)
Else
$SigGenFailed = True
EndIf
;---将签名应用到新建、转发、回复
If NOT $SigGenFailed = True AND Exist("%appdata%\Microsoft\Signatures\$SignatureFileName.htm") AND Exist("%appdata%\Microsoft\Signatures\$SignatureFileName.txt")
WriteValue("$ENUMKEY\$KeyNumber", "New Signature", $hexSignatureFileName, "REG_BINARY")
WriteValue("$ENUMKEY\$KeyNumber", "Reply-Forward Signature", $hexSignatureFileName, "REG_BINARY")
If @ERROR = 0
LogEvent(0, 0, "Outlook signature files and serial for account $EmailAccountName successfully updated to version $Serial for @WUSERID.", , "KiXtart")
$GenerateOutlookSig = True
Else
LogEvent(2, 0, "Failed to update Outlook signature serial for user @WUSERID!", , "KiXtart")
$GenerateOutlookSig = False
EndIf
Else
LogEvent(2, 0, "Failed to generate and/or write new signature files for user @WUSERID!", , "KiXtart")
$GenerateOutlookSig = False
EndIf
EndFunction
Function OutlookHexConvert($strInput)
$strInput = TxtToHex($strInput)
While $strInput <> ""
$OutlookHexConvert = $OutlookHexConvert + Left($strInput, 2) + "00"
$strInput = Right($strInput, Len($strInput) - 2)
Loop
$OutlookHexConvert = $OutlookHexConvert + "0000"
EndFunction
Function TxtToHex($strInput)
While $strInput <> ""
$char = Left($strInput, 1)
$ASCIIVal = asc($char)
$HexVal = $HexVal + DecToHex($ASCIIVal)
$TxtToHex = $TxtToHex + DecToHex($ASCIIVal)
$strInput = Right($strInput, Len($strInput) - 1)
Loop
EndFunction
到此在kixtart.kix里加入调用脚本,如下内容即: GenerateOutlookSig(neo123)
另外因为在线编辑的问题,原本一行代码造成N多换行,现我把原文件上传上来
下载地址:http://down.51cto.com/data/2336538
本文出自 “water-ice” 博客,请务必保留此出处http://windyma.blog.51cto.com/661702/1967125
以上是关于AD 脚本kixtart运用之六(outlook邮件批量生成签名)的主要内容,如果未能解决你的问题,请参考以下文章