我想在firestore中进行新预订时发送邮件,其中有一些数据用于测试目的,它现在只有firstName,lastName和email,但这并没有改变一件事。这应该发送一个文件在firestore中创建一个文件,但是它给了sendgrid但是我怎么能用gmail而不是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))
});
为了测试这个,我在我的firestore db中创建了一个新的预订
如何使用gmail而不是sendgrid来发送邮件,还是有其他方式我可以从客户端发送邮件,因为没有可能的后端?