2010-09-04 50 views
0

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

下面是示例代码:

变种outlookApp =新的ActiveXObject( “Outlook.Application”);

var nameSpace = outlookApp.getNameSpace(“MAPI”);

mailFolder = nameSpace.getDefaultFolder(6);

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

mailItem.Subject =“主题测试”;

mailItem.To =“[email protected]”;

mailItem.HTMLBody =“<b> bold </b >”;

mailItem.display(0);

是否有与Firefox相当的功能?例如与XPCom?有人有样品吗?

谢谢!

回答

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 = "[email protected]"; 
mailItem.HTMLBody = "<b>bold</b>"; 
mailItem.display (0); 

这里正在做的是使用<a>'s mailto:类似的方法:

<a href="mailto:[email protected]?subject=a+subject+test&body=%3Cb%3Ebold%3C/b%3E">email me!</a> 
+0

你是否已经测试此代码?我认为它不适用于Outlook。 mailto正文必须是纯文本格式,而不是html格式。 (RFC定义)Outlook将打印可读的HTML代码。 任何其他解决方案? – Mimefilt 2010-09-04 16:35:44

+0

我测试了它,但是我的雷鸟已禁用了html,所以我没有注意到这一点。我想不出另一种解决方案,但是我发现这个网页:http://www.angelfire.com/dc/html-webmaster/mailto.htm,它讨论了使用带有“”mailto:“action”的形式:“action:'< FORM方法= “邮报” 行动= “邮寄地址:[email protected]” ENCTYPE = “text/plain的”>'尝试与改变'文/ plain'为'文/ html',我不知道是怎么标准,或者它是否适用于HTML,但它值得一试。 (你可以用javascript构建一个临时表单并提交它,但是当然要先用html来确保它能正常工作)。 – aularon 2010-09-04 16:46:45

+0

感谢您的回答。 “正常”链接不适用于Outlook。 (它会适用于**一些** thunderbird版本,但不适用于outlook)我将在星期一尝试表单解决方案。 – Mimefilt 2010-09-04 16:51:17

0

这里是一个替代的解决方案非常相似,接受的答案,如果你使用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 = '[email protected]'; 
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性能良好的链接。