Newer
Older
import { ContactForm, Email } from './email';
const rabbitmqUrl = 'amqp://user:password123@rabbitmq:5672';
const mailerQueue = 'portail-data-send-email';
const email = new Email();
email.from = `${contactForm.firstname} ${contactForm.lastname} ${contactForm.from}`;
email.subject = contactForm.subject;
email.text = contactForm.text;
Logger.log(email);
return amqp.connect(rabbitmqUrl, (err, conn) => {
if (err != null) {
Logger.log(err);
return false;
} else {
// Create a communication channel
if (error != null) {
Logger.log(error);
return false;
} else {
// Stringify and bufferise message
const buffer = Buffer.from(JSON.stringify(email));
ch.assertQueue(mailerQueue, { durable: true });
ch.sendToQueue(mailerQueue, buffer, { persistent: true });
Logger.log(`sent to queue ${mailerQueue}: ${JSON.stringify(email)}`);