本文整理汇总了TypeScript中@sendgrid/mail.send函数的典型用法代码示例。如果您正苦于以下问题:TypeScript send函数的具体用法?TypeScript send怎么用?TypeScript send使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
recipients.forEach(recipient => {
if (birthdayMailing[0].emails.indexOf(recipient.email) === -1) {
bccList.push(recipient.email);
}
const birthdaySample = birthdayWishes[Math.floor(Math.random() * birthdayWishes.length)];
const mail: any = {
to: recipient.email,
bcc: bccList,
from: 'Geburtstage@sfwinterbach.com',
subject: 'Alles Gute zum Geburtstag!',
templateId: '780bf24e-b085-4ece-9262-f727c47a3edc',
substitutionWrappers: ['{{', '}}'],
substitutions: {
firstName: recipient.firstName,
lastName: recipient.lastName,
age: recipient.age,
message: birthdaySample.message,
author: birthdaySample.author
}
};
mailArray.push(sgMail.send(mail));
});
示例2: moment
.onPublish(async () => {
try {
const applicationsSnapshot = await admin.firestore().collection('applications')
.where('isCurrentApplication', '==', true)
.get();
const currentApp = applicationsSnapshot.docs[0].data();
const teamOfTheWeekMailing = currentApp.mailing.filter(mailing => {
return mailing.isActive && mailing.title === 'Mannschaft des Monats';
});
if (teamOfTheWeekMailing && teamOfTheWeekMailing.length > 0) {
const teamsSnapshot = await admin.firestore().collection('teams').get();
const sample = teamsSnapshot.docs[Math.floor(Math.random() * teamsSnapshot.size)];
await admin.firestore().collection(collectionString)
.doc(now.format('YYYY') + '-' + now.month())
.create({
assignedTeamId: sample.data().id,
title: now.format('YYYY') + '-' + now.month()
});
const current = moment().add(1, 'month');
const msg = {
to: teamOfTheWeekMailing[0].emails,
from: 'mitglieder@sfwinterbach.com',
subject: 'Mannschaft des Monats ' + now.format('MM') + '.' + now.format('YYYY'),
templateId: 'cd68a992-a76c-4b47-8dda-a7d9c68fd1b3',
substitutionWrappers: ['{{', '}}'],
substitutions: {
adminName: 'Thomas',
teamName: sample.data().title + ' (' + sample.data().subTitle + ')',
monthString: current.month() + '.' + now.format('YYYY')
}
};
return sgMail.send(msg);
} else {
console.warn('Kein Mail-Verteiler mit dem Namen "Mannschaft des Monats" gefunden');
return true;
}
} catch (e) {
console.error(e);
return e;
}
});
示例3:
.onCreate((event: any) => {
const msg = {
to: 'Thomas.handle@gmail.com',
from: 'admin@sfwinterbach.com',
subject: 'Neuer Benutzer',
templateId: '758f452a-aa4d-4664-8088-5a5ce2a814ac',
substitutionWrappers: ['{{', '}}'],
substitutions: {
email: event.email ? event.email : event.displayName,
name: 'Thomas',
siteName: 'sfwinterbach.com'
}
};
return sgMail.send(msg);
});
示例4: moment
.schedule('0 5 * * *').onRun(async context => {
try {
const monthDay = moment().format('MM-DD');
const mailArray: any = [];
const recipients: {
email: string,
firstName: string,
lastName: string,
age: number
}[] = [];
const appQuery = db.collection('applications').where('isCurrentApplication', '==', true);
const applicationsSnapshot = await appQuery.get();
const currentApp = applicationsSnapshot.docs[0].data();
const memberQuery = db.collection('members').where('mainData.birthday.monthDay', '==', monthDay);
const membersSnapshot = await memberQuery.get();
let birthdayList = '<ul>';
membersSnapshot.docs.forEach(function(doc) {
const memberData = doc.data();
const age = calculateAge(memberData.mainData.birthday.year, memberData.mainData.birthday.month, memberData.mainData.birthday.day);
if (memberData.contact && memberData.contact.email) {
const data = {
email: memberData.contact.email,
firstName: memberData.mainData.firstName,
lastName: memberData.mainData.lastName,
age: age
};
recipients.push(data);
}
birthdayList += '<li>' + memberData.mainData.firstName + ' ' + memberData.mainData.lastName + ' wird heute ' + age + ' Jahre</li>';
});
// if no there are no birthdays today
if (birthdayList === '<ul>') {
birthdayList = '<li>Heute hat niemand Geburtstag.</li>';
}
birthdayList += '</ul>';
const birthdayMailing = currentApp.mailing.filter(mailing => {
return mailing.isActive && mailing.title === 'GeburtstagsgrĂźĂe als Kopie';
});
if (birthdayMailing && birthdayMailing.length > 0) {
if (membersSnapshot.size > 0 && recipients.length === 0) {
const text = 'Es wurden keine Email Adressen der Geburtstagskinder hinterlegt.';
console.warn(text);
birthdayList += '<p>' + text + '</p>';
const mail: any = {
to: birthdayMailing[0].emails,
from: 'Geburtstage@sfwinterbach.com',
subject: 'Geburtstage vom ' + moment().format('LL'),
templateId: '3b21edd6-0c49-40c2-a2e3-68ae679ff440',
substitutionWrappers: ['{{', '}}'],
substitutions: {
adminName: '',
birthdayList: birthdayList,
dateString: moment().format('LL')
}
};
mailArray.push(sgMail.send(mail));
} else {
mailArray.push(sgMail.send({
to: birthdayMailing[0].emails,
from: 'Geburtstage@sfwinterbach.com',
subject: 'Geburtstage vom ' + moment().format('LL'),
templateId: '3b21edd6-0c49-40c2-a2e3-68ae679ff440',
substitutionWrappers: ['{{', '}}'],
substitutions: {
adminName: '',
birthdayList: birthdayList,
dateString: moment().format('LL')
}
}));
const bccList: string[] = [];
console.log(recipients);
recipients.forEach(recipient => {
if (birthdayMailing[0].emails.indexOf(recipient.email) === -1) {
bccList.push(recipient.email);
}
const birthdaySample = birthdayWishes[Math.floor(Math.random() * birthdayWishes.length)];
const mail: any = {
to: recipient.email,
bcc: bccList,
//.........这里部分代码省略.........
示例5: moment
.topic('members-of-the-week').onPublish(async () => {
try {
const now = moment();
const docId: string = now.week() + '-' + now.format('YY');
const applicationsSnapshot = await admin.firestore().collection('applications')
.where('isCurrentApplication', '==', true)
.get();
const currentApp = applicationsSnapshot.docs[0].data();
const membersOfTheWeekMailing = currentApp.mailing.filter(mailing => {
return mailing.isActive && mailing.title === 'Mitglieder der Woche';
});
if (membersOfTheWeekMailing && membersOfTheWeekMailing.length > 0) {
const memberSnapshot = await db.collection(collectionName).get();
const clubList = memberSnapshot.docs.filter((doc) => {
const member = doc.data();
return member.clubStatus && member.clubStatus > 0 && member.clubStatus !== 2;
});
const ahList = memberSnapshot.docs.filter((doc) => {
const member = doc.data();
return member.ahStatus && member.ahStatus > 0;
});
const playerList = memberSnapshot.docs.filter((doc) => {
const member = doc.data();
return member.dfbData && member.dfbData.playerStatus;
});
const honoraryList = memberSnapshot.docs.filter((doc) => {
const member = doc.data();
return member.clubStatus && member.clubStatus === 2;
});
if (!clubList && ahList && playerList && honoraryList) {
console.log({clubList, ahList, playerList, honoraryList});
return true;
}
const clubMember = clubList[Math.floor(Math.random() * clubList.length)].data();
const ahMember = ahList[Math.floor(Math.random() * ahList.length)].data();
const playerMember = playerList[Math.floor(Math.random() * playerList.length)].data();
const honoraryMember = honoraryList[Math.floor(Math.random() * honoraryList.length)].data();
const data = {
ah: {
id: docId,
type: 'ah',
year: now.format('YY'),
week: now.week(),
assignedMemberId: ahMember.id
},
club: {
id: docId,
type: 'club',
year: now.format('YY'),
week: now.week(),
assignedMemberId: clubMember.id
},
player: {
id: docId,
type: 'player',
year: now.format('YY'),
week: now.week(),
assignedMemberId: playerMember.id
},
honorary: {
id: docId,
type: 'honorary',
year: now.format('YY'),
week: now.week(),
assignedMemberId: honoraryMember.id
}
};
await db.collection('member-of-the-week').doc(docId).create(data);
const msg = {
to: membersOfTheWeekMailing[0].emails,
from: 'mitglieder@sfwinterbach.com',
subject: 'Mitglieder der Woche ' + now.week() + '/' + now.format('YY'),
templateId: 'fc184c8b-b721-450f-add7-69ef4d20fe10',
substitutionWrappers: ['{{', '}}'],
substitutions: {
adminName: '',
clubMember: 'Verein: ' + clubMember['mainData'] ? clubMember['mainData']['firstName'] + ' ' + clubMember['mainData']['lastName'] : ' ???',
ahMember: 'Alte Herren: ' + ahMember['mainData'] ? ahMember['mainData']['firstName'] + ' ' + ahMember['mainData']['lastName'] : ' ???',
player: 'Spieler: ' + playerMember['mainData'] ? playerMember['mainData']['firstName'] + ' ' + playerMember['mainData']['lastName'] : ' ???',
honorary: 'Ehrenmitglied: ' + honoraryMember['mainData'] ? honoraryMember['mainData']['firstName'] + ' ' + honoraryMember['mainData']['lastName'] : ' ???',
weekString: now.week(),
dateString: now.format('LL') + ' bis ' + now.add(6, 'days').format('LL')
}
};
return sgMail.send(msg);
//.........这里部分代码省略.........