jixuaa 发表于 2015-9-13 07:16:53

使用脚本写入OUTLOOK联系人

  因为客户的强烈要求,需在web中直接将数据库中的用户的联系人直接导入outlook,
部分实现代码如下:




<SCRIPT language=vbscript>
<!--
Set outLookApp = CreateObject(&quot;Outlook.Application&quot;)
Set outlookNS = outLookApp.GetNameSpace(&quot;MAPI&quot;)
set theContact = outlookNS.GetDefaultFolder(10)
set theContactItems = theContact.Items
set newContact = outLookApp.CreateItem(2)

newContact.LastName = &quot;neolee&quot;
newContact.FirstName = &quot;huan&quot;
newContact.MobileTelephoneNumber = &quot;13588888888&quot;

newContact.save
alert(newContact.LastName +&quot; &quot;+ newContact.FirstName + &quot;成功添加至outlook联系人!&quot;)
//-->
</SCRIPT>
  这段代码本来是用js来写的,但运行却通不过,代码如下:




<SCRIPT language=javascript>
outLookApp = new ActiveXObject(&quot;Outlook.Application&quot;);
outlookNS = outLookApp.GetNamespace(&quot;MAPI&quot;);
theContact = outlookNS.GetDefaultFolder(10);
theContactItems = theContact.Items;
newContact = outLookApp.CreateItem(2);

if(newContact in theContactItems)
alert(&quot;yes&quot;);
else
alert(&quot;no&quot;);
</SCRIPT>   
输出结果总是no,不知哪位大侠知道是何原因?

BTW:谢谢kaneboy提出用脚本来实现,本来想用OFFICE PIA来做的,那样就比较麻烦了!:)
页: [1]
查看完整版本: 使用脚本写入OUTLOOK联系人