无法使用带有多个附件的JS outlook activexobject发送电子邮件

时间:2014-04-03 07:03:52

标签: javascript

我试图使用带有多个附件的js outlook activexobject发送电子邮件。但是得到了对象错误。我可以使用单个附件发送电子邮件,但无法使用多个附件发送电子邮件。

I was trying the below code

function sendmail()
{
 var attachFilePath = document.getElementById('fPath').value;
    var theApp;  //Reference to Outlook.Application 
    var theMailItem; //Outlook.mailItem
    var attach1 = "C:\\Fusion\\Processed\\processed-28.3.2014.xls";
    var attach2= "C:\\Fusion\\Processed\\processed-13.3.2014.xls";
    console.log(-1);
    //Construct the Email including To(address),subject,body
    //var recipient
    var msg = "Hi Manish <br><br>please find the attachments <br><br>";
    //Create a object of Outlook.Application
    try {
        var theApp = new ActiveXObject("Outlook.Application");
        var objNS = theApp.GetNameSpace('MAPI');
        var theMailItem = theApp.CreateItem(0) // value 0 = MailItem
        //Bind the variables with the email
        // theMailItem.to = document.getElementById("errMailTo").value;
        theMailItem.to = "manish.b.yadav@accenture.com";
        theMailItem.Subject = "Testing Mail Sending With Multiple Attachments";
        theMailItem.Body = (msg);
        console.log(1);
        //theMailItem.Attachments[0]=attach1;
       theMailItem.Attachments.add(attach1);
        console.log(2);
       theMailItem.Attachments.add(attach2);
        console.log(3);
        theMailItem.display();
        theMailItem.send();
        //Show the mail before sending for review purpose
        //You can directly use the theMailItem.send() function
        //if you do not want to show the message.

    }
    catch (err) {
        alert(err); 
        alert("The following may have cause this error: \n" +
        "1. The Outlook express 2003 is not installed on the machine.\n" +
        "2. The msoutl.olb is not availabe at the location " +
        "C:\\Program Files\\Microsoft Office\\OFFICE11\\msoutl.old on client's machine " +
        "due to bad installation of the office 2003." +
        "Re-Install office2003 with default settings.\n" +
        "3. The Initialize and Scripts ActiveX controls not marked as safe is not set to enable.")
    }
    updateLastReadTime(); //update By manish To change Restart Logic time from 10 to 5
    // if (SendMail("manish.b.yadav@accenture.com", "mail.accenture.com", "John Smith", "manish.b.yadav@accenture.com", "Notification", "Hello Clare, Your application is nice.", "C:\\Fusion\\Processed\\processed-28.3.2014.xls", "C:\\Fusion\\Processed\\processed-13.3.2014.xls"))
      // console.log("Mail was sent");
    // else
      // console.warn("Mail was not sent"); 

}


Please help me in this regard


Thanks
Manish

1 个答案:

答案 0 :(得分:0)

调试时得到的确切错误是什么? 在我看来,我认为您的邮件服务器限制外发电子邮件的大小。 在某些情况下,如果附件是可执行文件,反病毒也可以限制发送电子邮件。