[英]Attachment base64 in emailjs
I use emailjs for sending email. 我使用emailjs发送电子邮件。 I have base64 string.
我有base64字符串。 When i send html body with
当我发送HTML正文
attachment:
[
{data:"<html> <body> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAFA3PEY8..."> </body> </html>", alternative:true}
]
Not all e-mail clients display the <img src="base64">
(eg gmail web or Outlook) 并非所有电子邮件客户端都显示
<img src="base64">
(例如gmail web或Outlook)
I want to attach a file from base64. 我想附加一个来自base64的文件。 How can I do it?
我该怎么做?
I tried so but the picture comes damaged: 我这样做了,但是图片损坏了:
attachment:
[
{data:"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAFA3PEY8...", encoded:true, name:"file.jpeg",type:"image/jpeg"},
]
PS: my server settings: PS:我的服务器设置:
"host" : "smtp.gmail.com",
"user" : "***@gmail.com",
"password" : "******",
"ssl" : true,
"port" : 465
Try to add the base64 string without the format data (I had the same problem but managed to fix it this way): 尝试添加没有格式数据的base64字符串(我也遇到了同样的问题,但是设法用这种方法解决了):
attachment:
[
{data:"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAFA3PEY8...", encoded:true, name:"file.jpeg",type:"image/jpeg"},
]
In other words, get the data string without anything else. 换句话说,获取数据字符串时不需任何其他操作。 You could use something like this to match it:
您可以使用类似这样的东西来匹配它:
var data = yourBase64DataUrl.match(/base64,(.+)$/);
var base64String = matches[1];
...
attachment: [
{data: base64String, encoded:true, name:"file.jpeg",type:"image/jpeg"},
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.