I want to send a mail when a new reservation is made in firestore with some data from there for testing purposes it's only firstName, lastName and email for now but that doesn't change a thing. This should send a mail on creation of a document in firestore but it gives with sendgrid but how can I change this to do this with gmail instead of sendgrid?
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as sgMail from '@sendgrid/mail';
admin.initializeApp(functions.config().firebase);
const SENDGRID_API_KEY = functions.config().sendgrid.key;
sgMail.setApiKey(SENDGRID_API_KEY);
exports.firestoreEmail = functions.firestore
.document('reservations/{reservationId}')
.onCreate(event => {
const reservationId = event.params.reservationId;
const db = admin.firestore();
return db.collection('reservations').doc(reservationId)
.get()
.then(doc => {
const reservation = doc.data();
const msg = {
to: reservation.mail,
from: 'my-email@gmail.com',
templateId: 'my-key',
substitutionWrappers: ['{{', '}}'],
substitutions: {
firstName: reservation.firstName,
lastName: reservation.lastName
}
};
return sgMail.send(msg)
})
.then(()=> console.log('email sent!'))
.catch(err => console.log(err))
});
To test this I create a new reservation in my firestore db
How do I use gmail instead of sendgrid for instance to send mails or is there any other way that I can send mails from clientside as there is no backend possible?