Compare commits

..

No commits in common. "21479635234692c6963545b39a32f5a39ac87434" and "18569d38d3d9315b47db9df75b8e7e1582c19658" have entirely different histories.

View File

@ -51,39 +51,34 @@ export const sendEmailWithAttachment = onRequest({
}); });
}); });
try { const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
const mailgun = new Mailgun(formData); const options = {
const client = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY }); wordwrap: 130,
};
const textMessage = convert(message, options);
const fileBuffer = fs.readFileSync(tempFilePath);
const attachmentFilename = fileName || path.basename(fileUrl.split('?')[0]);
const options = { const data = {
wordwrap: 130, from: process.env.MAILGUN_FROM_ADDRESS,
}; to: toAddress,
const textMessage = convert(message, options); subject: subject,
const fileBuffer = fs.readFileSync(tempFilePath); text: textMessage,
const attachmentFilename = fileName || path.basename(fileUrl.split('?')[0]); html: message,
attachment: {
data: fileBuffer,
filename: attachmentFilename,
contentType: 'application/pdf',
}
};
const data = { const result = await client.messages.create(process.env.MAILGUN_SERVER, data);
from: process.env.MAILGUN_FROM_ADDRESS, fs.unlinkSync(tempFilePath);
to: toAddress,
subject: subject,
text: textMessage,
html: message,
attachment: {
data: fileBuffer,
filename: attachmentFilename,
contentType: 'application/pdf',
}
};
const result = await client.messages.create(process.env.MAILGUN_SERVER, data); logger.info('Email with attachment from URL sent successfully');
fs.unlinkSync(tempFilePath); response.json({ success: true, result });
logger.info('Email with attachment from URL sent successfully');
response.json({ success: true, result });
} catch (e) {
console.error(`Error while sending E-mail. Error: ${e}`);
}
} catch (error) { } catch (error) {
logger.error('Error sending email with attachment from URL:', error); logger.error('Error sending email with attachment from URL:', error);
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) }); response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });