Skip to content

Commit

Permalink
Dienstag 17:10
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hornburger committed Oct 24, 2023
1 parent bae8605 commit 472acde
Showing 1 changed file with 70 additions and 60 deletions.
130 changes: 70 additions & 60 deletions src/routes/sendprotokollerouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class SendProtokolleroutsClass {
let tokenRequest;
let html;


this.sendprotokolllerouter.put('/', async (req: Request, res: Response) => {

tenantId = this.Config.TENANT_ID;
Expand Down Expand Up @@ -142,80 +141,91 @@ export class SendProtokolleroutsClass {
console.log('getdata ist ok');
console.log(getdata);

getdata.on('readable', () => {
if(typeof getdata.on !== 'undefined') {

while (null !== (chunk = getdata.read())) {
getdata.on('readable', () => {

filebuffer.push(chunk);
}
});
while (null !== (chunk = getdata.read())) {

getdata.on('end', () => {
filebuffer.push(chunk);
}
});

console.log('getdata.on(end)');
getdata.on('end', () => {

console.log('getdata.on(end)');

filedata = Buffer.concat(filebuffer).toString('base64');

Signatur = Signatur.replace('[Image]', 'data:image/png;base64,' + logoimageblob);

html = '<html lang="de">';
html += '<head title="Protokoll">';
html += '<title></title>';
html += '<style>';
html += 'body { font-family: Courier New; font-size: 15px; }';
html += '</style>';

html += '</head>';
html += '<body>';
html += this.FormatLinebreaks(Nachricht);
html += '<br><br>';
html += Signatur;
html += '</body>';
html += '</html>';

const sendMail: Mailmessagestruktur = {
message: {
subject: Betreff,
body: {
contentType: 'html',
content: html
},
toRecipients: ToRecipients,
attachments: [
{
"@odata.type": "#microsoft.graph.fileAttachment",
contentBytes: filedata,
name: Filename,
contentType: "application/pdf"
}
]
},
saveToSentItems: true
};

filedata = Buffer.concat(filebuffer).toString('base64');
if(CcRecipients.length > 0) sendMail.message.ccRecipients = CcRecipients;

Signatur = Signatur.replace('[Image]', 'data:image/png;base64,' + logoimageblob);
graphClient = Client.init({

html = '<html lang="de">';
html += '<head title="Protokoll">';
html += '<title></title>';
html += '<style>';
html += 'body { font-family: Courier New; font-size: 15px; }';
html += '</style>';
authProvider: done => {

html += '</head>';
html += '<body>';
html += this.FormatLinebreaks(Nachricht);
html += '<br><br>';
html += Signatur;
html += '</body>';
html += '</html>';
done(null, Token);
}
});

const sendMail: Mailmessagestruktur = {
message: {
subject: Betreff,
body: {
contentType: 'html',
content: html
},
toRecipients: ToRecipients,
attachments: [
{
"@odata.type": "#microsoft.graph.fileAttachment",
contentBytes: filedata,
name: Filename,
contentType: "application/pdf"
}
]
},
saveToSentItems: true
};

if(CcRecipients.length > 0) sendMail.message.ccRecipients = CcRecipients;

graphClient = Client.init({

authProvider: done => {

done(null, Token);
}
});
let emailurl = '/users/' + UserID + '/sendMail';

let emailurl = '/users/' + UserID + '/sendMail';
graphClient.api(emailurl).post(sendMail).then(() => {

graphClient.api(emailurl).post(sendMail).then(() => {
res.status(200).send({Message: 'Ok'});

res.status(200).send({Message: 'Ok'});
}).catch((mailerror: any) => {

}).catch((mailerror: any) => {
console.log('Protokoll senden fehlgeschlagen. Sendevorgang fehlerhaft: ' + mailerror.message);

console.log('Protokoll senden fehlgeschlagen. Sendevorgang fehlerhaft: ' + mailerror.message);

res.status(400).send({ Message: mailerror.message });
res.status(400).send({ Message: mailerror.message });
});
});
});

}
else {

console.log('getdata.on is undefined');

res.status(400).send({ Message: 'Object On Error' });
}

}
else {

Expand Down

0 comments on commit 472acde

Please sign in to comment.