2010-09-04 51 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性能良好的鏈接。