Reputation: 380
I use emailjs for sending email. I have base64 string. When i send html body with
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)
I want to attach a file from 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:
"host" : "smtp.gmail.com",
"user" : "***@gmail.com",
"password" : "******",
"ssl" : true,
"port" : 465
Upvotes: 3
Views: 3274
Reputation: 94
Try to add the base64 string without the format data (I had the same problem but managed to fix it this way):
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"},
]
Upvotes: 1