在 Javascript 中创建带有附件的电子邮件时出现问题 [英] Problem creating an email with an attachment in Javascript

查看:21
本文介绍了在 Javascript 中创建带有附件的电子邮件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过调用下面的代码并向其添加附件来发起电子邮件创建.

I'm initiating an email create, by calling the code below, and adding an attachment to it.

我希望用户能够输入收件人,并修改消息的内容,所以我不会立即发送.

I want the user to be able to type in the receipient, and modify the contents of the message, so I'm not sending it immediately.

为什么第二次调用该方法时会出现 RangeError?
(第一次正常工作.)

Why do I get a RangeError the 2nd time the method is called?
(The first time it works correctly.)

function NewMailItem(p_recipient, p_subject, p_body, p_file, p_attachmentname)
{
   try 
   {
     var objO = new ActiveXObject('Outlook.Application');
     var objNS = objO.GetNameSpace('MAPI');
     var mItm = objO.CreateItem(0);
     mItm.Display();
     if (p_recipient.length > 0) 
     {
       mItm.To = p_recipient;
     }
     mItm.Subject = p_subject;
     if (p_file.length > 0) 
     {
      var mAts = mItm.Attachments;
      mAts.add(p_file, 1, p_body.length + 1, p_attachmentname);
     }
     mItm.Body = p_body;
     mItm.GetInspector.WindowState = 2;
   } catch(e) 
   { 
     alert('unable to create new mail item'); 
   } 
}

错误发生在 mAts.add 行上.所以当它尝试附加文档时,它失败了.

The error is occuring on the mAts.add line. So when it tries to attach the document, it fails.

文件名 (p_file) 也是图像的 http 地址.

Also the file name (p_file) is a http address to a image.

推荐答案

在 IE 之外无法工作,用户需要在机器上安装 Outlook 并在其上配置一个帐户.您确定要以这种方式发送电子邮件吗?

Won't work outside of IE, the user needs to have Outlook on the machine and an account configured on it. Are you sure you want to send an email this way?

这篇关于在 Javascript 中创建带有附件的电子邮件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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