使用Javascript在Microsoft Outlook中创建HTML电子邮件 [英] Use Javascript to create an HTML email in Microsoft Outlook

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

问题描述

我想从Javascript网络应用程序创建一封电子邮件。我完全了解这方面的许多问题(例如 Open Outlook带Chrome的HTML )。典型答案存在问题:

I'd like to create an email from a Javascript web application. I'm completely aware of the many SO questions on this (e.g. Open Outlook HTML with Chrome). There are problems with the typical answers:


  1. Mailto:link:这将允许您创建电子邮件,但仅限于纯文本(没有HTML)并且它不允许附件。

  1. Mailto: link: This will let you create an email, but only in plain text (no HTML) and it does not allow for attachments.

Activex:仅限IE,我的应用程序也需要在Firefox和Chrome中运行。 FF&允许使用ActiveX的Chrome插件存在安全隐患,而且似乎有问题。

Activex: IE only, my application needs to run in Firefox and Chrome too. FF & Chrome plug-ins to allow ActiveX are security hazards and seem to be buggy.

服务器端通过SMTP发送:电子邮件不会在发送给用户的文件夹。加上障碍让用户在浏览器中编辑HTML并附加文件。

Server-side sends via SMTP: The email does not end up in the "Sent" folder for the user. Plus hurdles letting the user edit HTML in the browser and attach files.

创建一个Outlook .MSG文件:似乎没有库,也没有关于做的文章这个。显然,文件格式实际上嵌入了整个FAT文件存储系统。

Create an Outlook .MSG file: There seem to be no libraries and little written about doing this. Apparently the file format actually has an entire FAT file storage system embedded.

关键差异在我和其他许多SO问题之间:

Key differences between many other SO questions and mine:


  • 可以访问客户机,所以我可以安装
    帮助应用程序或加载项,根据需要更改设置等。

  • 接口需要实际发送邮件,它只需要
    为用户设置。

  • 我还需要能够通过电子邮件向JS发送附件(例如PDF)。

  • I do have access to the client machines, so I could install helper applications or add-ins, change settings as needed, etc.
  • The interface does not need to actually send the mail, it only needs to set it up for the user.
  • I also need to be able to give the email an attachment from JS (e.g. a PDF).

我不能成为第一个面对此问题的网络应用开发者,但我无法找到商业或开源的解决方案。

I cannot be the first web app developer to face this and yet I'm unable to find a solution either commercial or open source.

更新:

我使用了EML文件方法,到目前为止效果很好。这是我创建和触发它的JS代码:

I used the EML file method and it works well so far. Here's my JS code to create and trigger it:

var emlContent = "data:message/rfc822 eml;charset=utf-8,";
emlContent += 'To: '+emailTo+'\n';
emlContent += 'Subject: '+emailSubject+'\n';
emlContent += 'X-Unsent: 1'+'\n';
emlContent += 'Content-Type: text/html'+'\n';
emlContent += ''+'\n';
emlContent += htmlDocument;

var encodedUri = encodeURI(emlContent); //encode spaces etc like a url
var a = document.createElement('a'); //make a link in document
var linkText = document.createTextNode("fileLink");
a.appendChild(linkText);
a.href = encodedUri;
a.id = 'fileLink';
a.download = 'filename.eml';
a.style = "display:none;"; //hidden link
document.body.appendChild(a);
document.getElementById('fileLink').click(); //click the link


推荐答案

MSG文件格式为记录,但肯定不好玩......
为什么不创建EML(MIME)文件?

MSG file format is documented, but it is certainly not fun... Why not create an EML (MIME) file?

对于想要删除或拒绝此答案的人:建议使用EML(MIME)格式。根据OP,他考虑了MSG文件格式(#4),但由于复杂性或缺乏处理该格式的JS库而不鼓励。如果考虑MSG文件,MIME是一个更好的选择 - 它是基于文本的,因此创建它不需要特殊的库。 Outlook将能够像MSG文件一样轻松地打开它。要确保Outlook将其视为未发送的邮件,请将 X-Unsent MIME标头设置为1.

To those who want to delete or downvote this answer: the suggestion is to use the EML (MIME) format. According to the OP, he considered the MSG file format (#4), but was discouraged due to complexity or lack of JS libraries that process that format. If MSG file was considered, MIME is a much better choice - it is text based, so no special libraries are required to create it. Outlook will be able to open it just as easily as an MSG file. To make sure it is treated as an unsent message by Outlook, set the X-Unsent MIME header to 1.

更新:最简单的EML文件如下所示:

UPDATE: The simplest EML file would look like the following:

To: Joe The User <joe@domain.demo>
Subject: Test EML message
X-Unsent: 1
Content-Type: text/html

<html>
<body>
Test message with <b>bold</b> text.
</body>
</html>

这篇关于使用Javascript在Microsoft Outlook中创建HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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