Dav*_*wen 4 html javascript email outlook internet-explorer
我在内部使用Web应用程序的企业环境中工作,并要求在用户Outlook中生成一封电子邮件,保留其签名,以便他们可以根据需要进行修改并自行发送.
所有用户都在IE8 +上,并且该站点是启用了ActiveX对象的可信站点的一部分,因此我希望使用Outlook自动化来实现此目的.
以下是我将此与现有问题区分开来的要求的快速摘要.
Dav*_*wen 13
如果站点是可信站点并且启用了ActiveX对象,则可以使用IE中的JavaScript来实现此目的.我已经让这个脚本工作到IE6并且测试到IE10我不确定它在IE11中的支持.
下面脚本的一个重点是,您必须Display在尝试从中提取签名或尝试设置其之前调用电子邮件,HTMLBody否则您将丢失签名信息.
try {
//get outlook and create new email
var outlook = new ActiveXObject('Outlook.Application');
var email = outlook.CreateItem(0);
//add some recipients
email.Recipients.Add('user1@company.com').Type = 1; //1=To
email.Recipients.Add('user2@company.com').Type = 2; //2=CC
//subject and attachments
email.Subject = 'A Subject';
//email.Attachments.Add('URL_TO_FILE', 1); //1=Add by value so outlook downloads the file from the url
// display the email (this will make the signature load so it can be extracted)
email.Display();
//use a regular expression to extract the html before and after the signature
var signatureExtractionExpression = new RegExp('/[^~]*(<BODY[^>]*>)([^~]*</BODY>)[^~]*/', 'i');
signatureExtractionExpression.exec(email.HTMLBody);
var beforeSignature = RegExp.$1;
var signature = RegExp.$2;
//set the html body of the email
email.HTMLBody = beforeSignature + '<h1>Our Custom Body</h1>' + signature;
} catch(ex) {
//something went wrong
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14806 次 |
| 最近记录: |