从IE网站打开html正文的Outlook的新电子邮件 [英] Open new email in outlook with html body from IE web site

查看:1215
本文介绍了从IE网站打开html正文的Outlook的新电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个内部使用的Web应用程序的企业环境中工作,并且要求在用户Outlook中生成电子邮件,保留他们的签名,以便随后可以根据需要进行修改并自行发送。

I am working in a corporate environment on an internal use web application and have a requirement to generate an email in the users Outlook retaining their signature so that they can then modify if required and send it themselves.

所有用户都在IE8 +,该网站是启用ActiveX对象的受信任站点的一部分,因此我希望使用Outlook自动化来实现此目的。

All users are on IE8+ and the site is a part of Trusted Sites with ActiveX objects enabled so I was hoping to use outlook automation to achieve this.

以下是我要区分现有问题的要求的简要摘要。

Here is a quick summary of my requirements to differentiate this from existing questions.


  • 只需要支持IE8 +和Outlook

  • HTML正文格式支持

  • 附件支持

  • 必须保留用户配置的签名

推荐答案

如果网站是受信任的站点,并且启用了ActiveX对象,则可以在IE中使用JavaScript实现。我已经有这个脚本工作远远的IE6和测试到IE10我不确定它在IE11的支持。

This can be achieved using JavaScript in IE if the site is a Trusted Site and ActiveX objects are enabled. I have had this script work as far back as IE6 and tested up to IE10 I am unsure about its support in IE11.

下面的脚本关键是你在尝试从其中提取签名或尝试设置其 HTMLBody 之前,请先在电子邮件中调用显示,否则您将丢失签名信息。

An important point about the script below is that you must call Display on the email before trying to extract the signature from it or trying to set its HTMLBody otherwise you will lose the signature information.

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
}

这篇关于从IE网站打开html正文的Outlook的新电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆