aws-sdk#SES TypeScript Examples

The following examples show how to use aws-sdk#SES. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: helpers.ts    From crossfeed with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
sendEmail = async (
  recipient: string,
  subject: string,
  body: string
) => {
  const transporter = nodemailer.createTransport({
    SES: new SES({ region: 'us-east-1' })
  });

  await transporter.sendMail({
    from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER!,
    to: recipient,
    subject: subject,
    text: body,
    replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!
  });
}
Example #2
Source File: createAuthChallenge.ts    From office-booker with MIT License 6 votes vote down vote up
async function sendEmail(
  domain: string,
  emailAddress: string,
  secretLoginCode: string,
  fromAddress: string
) {
  const params: SES.SendEmailRequest = {
    Destination: { ToAddresses: [emailAddress] },
    Message: {
      Body: {
        Html: {
          Charset: 'UTF-8',
          Data: verifyHTML(domain, secretLoginCode),
        },
        Text: {
          Charset: 'UTF-8',
          Data: verifyText(secretLoginCode),
        },
      },
      Subject: {
        Charset: 'UTF-8',
        Data: 'Office Booker - Verify',
      },
    },
    Source: fromAddress,
  };

  console.log(JSON.stringify(params, null, 2));

  const ses = new SES();

  await ses.sendEmail(params).promise();
}
Example #3
Source File: createBooking.ts    From office-booker with MIT License 6 votes vote down vote up
sendNotificationEmail = async (
  emailAddress: string,
  fromAddress: string,
  date: string,
  user: string,
  office: string,
  reasonToBook: string
) => {
  const formattedDate = format(parseISO(date), 'dd/MM/yyyy');

  const params: SES.SendEmailRequest = {
    Destination: { ToAddresses: [emailAddress] },
    Message: {
      Body: {
        Text: {
          Charset: 'UTF-8',
          Data: `Date: ${formattedDate}\nUser: ${user}\nOffice: ${office}\n\nReason for booking:\n${reasonToBook}`,
        },
      },
      Subject: {
        Charset: 'UTF-8',
        Data: `Office Booker - ${formattedDate} | ${user} | ${office}`,
      },
    },
    Source: fromAddress,
  };

  const ses = new SES();

  return await ses.sendEmail(params).promise();
}
Example #4
Source File: ses.provider.ts    From loopback4-notifications with MIT License 6 votes vote down vote up
constructor(
    @inject(NotificationBindings.Config, {
      optional: true,
    })
    private readonly config?: INotificationConfig,
    @inject(SESBindings.Config, {
      optional: true,
    })
    private readonly sesConfig?: SES.Types.ClientConfiguration,
  ) {
    if (this.sesConfig) {
      this.sesService = new SES(this.sesConfig);
    } else {
      throw new HttpErrors.PreconditionFailed('AWS SES Config missing !');
    }
  }
Example #5
Source File: ses.provider.ts    From loopback4-notifications with MIT License 5 votes vote down vote up
value() {
    return {
      publish: async (message: SESMessage) => {
        const fromEmail =
          message.options?.fromEmail || this.config?.senderEmail;

        if (!fromEmail) {
          throw new HttpErrors.BadRequest(
            'Message sender not found in request',
          );
        }

        if (message.receiver.to.length === 0) {
          throw new HttpErrors.BadRequest(
            'Message receiver not found in request',
          );
        }
        if (!message.subject || !message.body) {
          throw new HttpErrors.BadRequest('Message data incomplete');
        }

        if (this.config?.sendToMultipleReceivers) {
          const receivers = message.receiver.to.map(receiver => receiver.id);
          const emailReq: SES.SendEmailRequest = {
            Source: fromEmail || '',
            Destination: {
              ToAddresses: receivers,
            },
            Message: {
              Subject: {
                Data: message.subject ?? '',
              },
              Body: {
                Html: {
                  Data: message.body || '',
                },
              },
            },
          };
          await this.sesService.sendEmail(emailReq).promise();
        } else {
          const publishes = message.receiver.to.map(receiver => {
            const emailReq: SES.SendEmailRequest = {
              Source: fromEmail || '',
              Destination: {
                ToAddresses: [receiver.id],
              },
              Message: {
                Subject: {
                  Data: message.subject ?? '',
                },
                Body: {
                  Html: {
                    Data: message.body || '',
                  },
                },
              },
            };
            return this.sesService.sendEmail(emailReq).promise();
          });

          await Promise.all(publishes);
        }
      },
    };
  }
Example #6
Source File: ses.provider.ts    From loopback4-notifications with MIT License 5 votes vote down vote up
sesService: SES;