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

查看:79
本文介绍了使用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天全站免登陆