我有一个为iOS iPresent应用程序编写的JavaScript应用程序。它为用户提供了一些计算。最后,结果将被采用并以电子邮件形式发送为纯文本。此行为以下列方式实现:
var emailSubject = 'Subject';
//email template
var emailMessage = '' +
'Dear Mr. / Mrs.,[BR]' +
'[BR]' +
'Lorem ipsum ...' +
'[BR]' +
Your result is: '[RESULT]'
;
以下功能采用电子邮件模板,填充数据,然后打开邮件对话框。
openMailbox: function() {
var message,
Message,
br = '%0D%0A'
;
message = emailMessage
.replace(/\[BR\]/g, '%0D%0A' )
.replace(/\[RESULT\]/g, result )
.replace(/&/, '%26')
Message = '' +
'mailto:' +
'?subject=' + emailSubject +
'&body=' + message
;
window.location.href = Message;
},
此类电子邮件只是一个纯文本。是否有可能以某种方式增强电子邮件的外观?添加一些样式,例如,在其中附加图像或pdf文件,但仅使用JavaScript,HTML,CSS等前端技术?
答案 0 :(得分:0)
要清楚。电子邮件由几部分组成:
在客户端上,您应该只生成消息正文。好吧,理论上你可以在那里构建整个字母(添加所有需要的标题),然后将其传递给邮件服务器,但很可能它不是一个好的解决方案。
后端是更好的地方,你应该只传递电子邮件正文。
再一次,理论上你可以通过从图像生成一个base 64字符串并将其附加到带有所需标题的字母,理论上你可以添加图像附件到邮件正文,如下所示:
------------F81BD43094AAFAF6EC4AE17F5F68753C
Content-Transfer-Encoding: base64
Content-Type: image/png; filename="facebook.png"
Content-Disposition: inline; charset=utf-8; filename="facebook.png"
Content-ID: <facebook.png>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAA9xJREFUeNrEV0toE1EUvUkmxJpEUHQjaFuL9VM34ocWFNEqCrpo60oq
uHNhET8guBDcaEEXgrgRtwoi+Fsp6sZlKYpaSWljqzGmiqS22lKbzudd582beXlvZt70g+Klycz7
nvvOPffmNYaI0NJ+uXNsEq/qFq4Eu80M2cf5o19eG0PaBPg6/7jb5+3J3rCQiMXOfu65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07UyMblDb
fKrdIniN/q82x1wMtZYta313wmnI5UthUwsUvNR74/EfAQYA2LBjPIifyRUAAAAASUVORK5CYII=
但在这种情况下,你不仅要创建字母的主体,还要创建字母本身,它还需要其他标题。像:
Delivered-To: email@email.com
Return-Path: <email@email.com>
From: =?utf-8?B?0JDQu9C10LrRgdCw0L3QtNGA?= <email@email.com>
Subject: =?utf-8?B?YWRhZA==?=
------------F81BD43094AAFAF6EC4AE17F5F68753C
Content-Type: multipart/alternative; boundary="----------30F28BDC77E3693E345BC2E04E6615BC"
------------30F28BDC77E3693E345BC2E04E6615BC
Content-Type: text/html; charset=utf-8
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head></head>
<body><div align=left>MESSAGE BODY</div>
<hr size=1><div align=left style="height:25px">