Compare commits

..

No commits in common. "f8b3930fcc7376b6594d100d5dadf679675ebca4" and "103684dc4f5f04b52cf085cb67ed02d92d489753" 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 client = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
const options = {
wordwrap: 130,
};
const textMessage = convert(message, options);
const fileBuffer = fs.readFileSync(tempFilePath);
const attachmentFilename = fileName || path.basename(fileUrl.split('?')[0]);
const options = {
wordwrap: 130,
};
const textMessage = convert(message, options);
const fileBuffer = fs.readFileSync(tempFilePath);
const attachmentFilename = fileName || path.basename(fileUrl.split('?')[0]);
const data = {
from: process.env.MAILGUN_FROM_ADDRESS,
to: toAddress,
subject: subject,
text: textMessage,
html: message,
attachment: {
data: fileBuffer,
filename: attachmentFilename,
contentType: 'application/pdf',
}
};
const data = {
from: process.env.MAILGUN_FROM_ADDRESS,
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);
fs.unlinkSync(tempFilePath);
const result = await client.messages.create(process.env.MAILGUN_SERVER, data);
fs.unlinkSync(tempFilePath);
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}`);
}
logger.info('Email with attachment from URL sent successfully');
response.json({ success: true, result });
} catch (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) });