Trying to send a generated PDF from eKoopman's HTML2PDF.js to send as an email attachment-- but can't get the resulting PDF to display. Have tried a lot of the solutions on Stack Overflow and elsewhere, but many tend to be outdated.
HTML2PDF:
html2pdf().set(opt).from(iac).toPdf().output('datauristring')
.then(function(pdf) {
emailDoc(pdf)
})
Attempts at the relevant parts of the mail options from emailDoc():
attachments: [{
filename: 'Name.pdf',
content: Buffer.from(pdf).toString('base64')
}]
attachments: [{
filename: 'Name.pdf',
content: Buffer.from(pdf).toString('base64'),
contentType: 'application/pdf'
}]
attachments: [{
filename: 'Name.pdf',
content: new Buffer(pdf, 'base64'),
contentType: 'application/pdf'
}]
attachments: [{
filename: 'Name.pdf',
content: pdf,
encoding: 'base64'
}]
Doesn't necessarily have to be the base64 method, just any combination that will make this work!
You may try to save your pdf first, then upload it using path description like,
attachments: [{
filename: 'file.pdf',
path: '/path/to/file',
contentType: 'application/pdf'
}],
Hope it helps!
Related
my schema look like
var GameData = new Schema({
title: {
type: String,
unique: true
},
game_template: {
type: Schema.Types.ObjectId,
ref: 'GameTemplate',
index: true
},
data:{
type: Schema.Types.Mixed
}]
now i handle images or url array of images
but my data type is mixed type
if image came means store s3buckut and save db
or if url came means i saved directly
Below is the message object used to send emails.
message = {
to: toEmail,
from: emailInfo.emailFromAddress,
subject: emailInfo.emailSubjectTemplate,
attachments: [
{
filename: fileName,
content: base64str,
contentId: fileName,
disposition: "attachment"
}
],
html: emailMessageBodyTemplate
};
The content is encoded into a base64 string by the following below code.
const base64_encode = file => {
var bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString("base64");
};
I don't know where I m going wrong but I'm getting the error as follows.
message:"The content value must be a string at least one character in length."
but the content is not empty when I debug it is a base64 string.
Please help.
On this page it describes exactly your error.
I believe in this error content means your message or a text as error describes
You may not send an email with no content.
And as per the API docs,you are missing a required parameter content.
message = {
to: toEmail,
from: emailInfo.emailFromAddress,
subject: emailInfo.emailSubjectTemplate,
content:[
{
type : 'string',
value : 'message'
}
],
attachments: [
{
filename: fileName,
content: base64str,
contentId: fileName,
disposition: "attachment"
}
],
html: emailMessageBodyTemplate
};
Hope this helps.
I've encountered the same issue and in my case I used 'xlsx' npm lib, to implement the solution as follow:
const workbook = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(workbook, ws, 'Accounts');
// write the file in base64 format
const report = XLSX.write(workbook, { type: 'base64', compression: true });
const attachment = {
content: report,
filename: `MyReport.xlsx`,
type: 'text/html',
disposition: 'attachment'
};
I'm trying to send an e-mail with an attachment using Nodemailer. No matter what I do, if I specify an attachments property, the e-mail comes up empty (no attachments, no html, no text). Sending an e-mail without any attachments works as expected. Here's the code I have so far:
transporter.sendMail({
to: `${toTitleCase(i.nome)} <${i.email}>`,
subject: 'Treinamentos',
text: 'hello!',
html: `Embedded image: <img src="cid:nyan#example.com"/>`,
attachments: [
{
filename: 'newimg.jpg',
path: __dirname + '/src/img/newimg.jpg',
cid: 'nyan#example.com'
}
]
}, (err, info )=> {
console.log(err);
console.log(info);
});
I have also tried using content instead of path, same result. I should also note that the err callback is empty.
I figured it out. I had set 'Content-type': 'text/html; charset=UTF-8' as the header on the transporter object. Removing that line fixed the issue.
I have picture in "Uint8arrary" and I would like to send this in email attachment.
In my js:
attachments: [{
content: fileInfo.fileContent, // Uint8arrary
filename: 'project',
encoding: 'binary'
}]
But this doesn't work.
I am new to Sencha Touch framework. I need to load some data from an XML file into a List. Right now I am just trying to make the XMLReader example given in the documentation work.
When I try to run the below mentioned code, I get an error message:
Javascript error on Line 7212
sencha-touch-debug.js
TypeError: Result of expression 'records' [undefined] is not an object.
Code - index.js:
Ext.setup({
onReady: function(){
Ext.regModel('User1', {
fields: ['id', 'name','email']
});
var temp = new Ext.data.Store({
model: 'User',
autoLoad:true,
proxy: {
type: 'ajax',
url : 'users.xml',
reader: {
type: 'xml',
record: 'user'
}
}
});
var list = new Ext.List({
fullscreen: true,
itemTpl : '{id} {name}',
store: temp
});
list.show();
}
});
users.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<id>1</id>
<name>Ed Spencer</name>
<email>ed#sencha.com</email>
</user>
<user>
<id>2</id>
<name>Abe Elias</name>
<email>abe#sencha.com</email>
</user>
</users>
I know its a very small thing that I am missing, but I'm not sure what it is. I tried the solution mentioned in this post, but it doesn't work for me.
I dit notice you didn't define the root node of the xml file.
var temp = new Ext.data.Store({
model: 'User',
autoLoad:true,
proxy: {
type: 'ajax',
url : 'users.xml',
reader: {
type: 'xml',
record: 'user',
root: 'users'
}
}
});
Not sure if this is the only thing, try it out and let me know!