當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mail.send函數代碼示例

本文整理匯總了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));
          });
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:25,代碼來源:birthday-reminder.ts

示例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;
    }
  });
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:49,代碼來源:team-of-the-month.ts

示例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);
  });
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:17,代碼來源:user-created.ts

示例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,
//.........這裏部分代碼省略.........
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:101,代碼來源:birthday-reminder.ts

示例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);
//.........這裏部分代碼省略.........
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:101,代碼來源:member-of-the-week.ts


注:本文中的@sendgrid/mail.send函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。