【问题标题】:Create Outlook Object with Firefox使用 Firefox 创建 Outlook 对象
【发布时间】:2010-09-04 11:14:59
【问题描述】:

使用 ActiveX,我可以创建一个 Outlook 实例并开始一个新的 HTML 电子邮件。

这里是示例代码:

var outlookApp = new ActiveXObject("Outlook.Application");

var nameSpace = outlookApp.getNameSpace("MAPI");

mailFolder = nameSpace.getDefaultFolder(6);

mailItem = mailFolder.Items.add('IPM.Note.FormA');

mailItem.Subject="一个主题测试";

mailItem.To = "an@email.here";

mailItem.HTMLBody = "粗体";

mailItem.display (0);

是否有 Firefox 的等价物。例如与 XPCom?请问有人有样品吗?

谢谢!

【问题讨论】:

    标签: javascript firefox outlook activex


    【解决方案1】:
    //this class emulates the one u used to use
    function mailer() {
      this.display = function() {
        var url = 'mailto:'
                           + this.To
                           + '?subject=' + encodeURIComponent(this.Subject)
                           + '&body=' + encodeURIComponent(this.HTMLBody);
        window.location = url;
      }
    }
    
    //we instantiate
    mailItem = new mailer();
    
    
    //and then your old code: 
    mailItem.Subject="a subject test";
    mailItem.To = "an@email.here";
    mailItem.HTMLBody = "<b>bold</b>";
    mailItem.display (0);
    

    这里正在做的是使用&lt;a&gt;'s mailto:类似的方法:

    <a href="mailto:an@email.here?subject=a+subject+test&body=%3Cb%3Ebold%3C/b%3E">email me!</a>
    

    【讨论】:

    • 你已经测试过这段代码了吗?我认为它不适用于 Outlook。 mailto 正文必须是纯文本而不是 html。 (RFC 定义)Outlook 将打印可读的 HTML 代码。还有其他解决方案吗?
    • 我测试了它,但我的雷鸟禁用了 html,所以我没有注意到。我想不出另一种解决方案,但是我找到了这个页面:angelfire.com/dc/html-webmaster/mailto.htm,它谈论使用带有"mailto:" 操作的表单:&lt;FORM method="post" action="mailto:noone@snai1mai1.com" enctype="text/plain"&gt; 尝试将text/plain 更改为text/html,我不确定有多标准是这样还是它是否适用于 HTML,但值得一试。 (您可以使用 javascript 构建一个临时表单并提交它,但当然首先尝试使用 html 以确保它有效)。
    • 感谢您的回答。 “正常”链接不适用于 Outlook。 (它适用于 一些 雷鸟版本,但不适用于 Outlook)我将在星期一尝试表单解决方案。
    • 恐怕。没有运气)=请有其他解决方案
    【解决方案2】:

    如果您使用 jQuery 并希望扩展其功能来实现此目的,这里有一个与公认答案非常相似的替代解决方案。与其他答案一样好,但我认为我会抛出我使用的替代解决方案。到目前为止,我在跨浏览器使用方面没有任何问题。我没有回去尝试旧版本的 IE,只是使用每个浏览器的更新版本来测试。

    扩展 jQuery 以包含您的自定义邮件功能

    $(function () {
        $.fn.myMailer = function () {
            this.display = function() {
                var url = 'mailto:' + this.To + 
                          '?subject=' + encodeURIComponent(this.Subject) + 
                          '&body=' + encodeURIComponent(this.HTMLBody);
                window.location = url;
                return true;
            }
        }
    });
    

    示例用法:

    var myMailItem = new $.fn.myMailer();
    myMailItem.To = 'yourEmail@domain.com';
    myMailItem.Subject = 'Your Subject';
    myMailItem.HTMLBody = 'Whatever you want your E-Mail to say';
    myMailItem.display(0);
    

    此外,如果您想添加 CCBCC 收件人,请按照上面的结构将它们添加到 mailto 查询字符串中好吧。

    我还尝试在客户端计算机上的 Outlook 电子邮件中获取附件

    $(function () {
        $.fn.myMailer = function () {
            this.display = function() {
                var url = 'mailto:' + this.To + '?content-type=' +
                           encodeURIComponent('multipart/form-data') + 
                          '&subject=' + encodeURIComponent(this.Subject) + 
                          '&body=' + encodeURIComponent(this.HTMLBody) +  
                          '&attachment=' + encodeURIComponent(this.Attachment);
                window.location = url;
                return true;
            }
        }
    });
    

    我的尝试失败了。我不确定这是否可能仅来自使用客户端代码。我可能是错的。如果可能的话,我认为这也可能构成安全威胁。

    我想说这里最好的选择是使用客户端脚本来调用一些服务器端代码,但是您更愿意这样做并让服务器发送电子邮件(如果适用)。

    但是,我需要将附件添加到 Outlook 电子邮件中,该电子邮件会在客户端计算机上弹出,因此我仍在研究如何根据我的情况处理添加附件的最终细节。使用 .NET 我认为应该有一些方法来处理这个我只是还没有时间实现服务器端处理程序来完成它。如果其他人正在尝试使用 .NET 完成同样的事情,here 是开始使用 Outlook 2013 MailItem 属性的好链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 2018-12-07
      相关资源
      最近更新 更多