nodemailer#createTransport TypeScript Examples

The following examples show how to use nodemailer#createTransport. 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: emails.ts    From one-platform with MIT License 6 votes vote down vote up
emailTransport = createTransport({
  host: SMTP_HOST,
  port: SMTP_PORT,
  secure: false,
  tls: {
    rejectUnauthorized: false, // do not fail on invalid certs
  },
  logger: false,
  transactionLog: false,
  debug: false, // include SMTP traffic in the logs
  disableFileAccess: true,
  disableUrlAccess: true,
})
Example #2
Source File: mailer.service.ts    From rest-api.ts with MIT License 6 votes vote down vote up
protected async initializeTransporter() {
    if (MailerService.transporter !== undefined) {
      return;
    }

    let {user, pass} = await createTestAccount();

    MailerService.transporter = createTransport({
      host: 'smtp.ethereal.email',
      port: 587,
      secure: false,
      auth: {user, pass},
    });
  }
Example #3
Source File: Misc.ts    From vircadia-metaverse with Apache License 2.0 6 votes vote down vote up
export async function SendVerificationEmail(pAccount: AccountEntity, pVerifyCode: string): Promise<void> {
    try {
        const verificationURL = Config.metaverse['metaverse-server-url']
                + `/api/v1/account/verify/email?a=${pAccount.id}&v=${pVerifyCode}`;
        const metaverseName = Config.metaverse['metaverse-name'];
        const shortMetaverseName = Config.metaverse['metaverse-nick-name'];

        const verificationFile = path.join(__dirname, '../..', Config['metaverse-server']['email-verification-email-body']);
        Logger.debug(`SendVerificationEmail: using verificationFile from ${verificationFile}`);
        let emailBody = await fsPromises.readFile(verificationFile, 'utf-8');
        emailBody = emailBody.replace('VERIFICATION_URL', verificationURL)
            .replace('METAVERSE_NAME', metaverseName)
            .replace('SHORT_METAVERSE_NAME', shortMetaverseName);

        Logger.debug(`SendVerificationEmail: SMTPhost=${Config['nodemailer-transport-config'].host}`);
        const transporter = createTransport(Config['nodemailer-transport-config']);
        if (transporter) {
            Logger.debug(`SendVerificationEmail: sending email verification for new account ${pAccount.id}/${pAccount.username}`);
            const msg = {
                from: Config['metaverse-server']['email-verification-from'],
                to: pAccount.email,
                subject: `${shortMetaverseName} account verification`,
                html: emailBody
            };
            transporter.sendMail(msg);
            transporter.close();
        }
        else {
            Logger.error(`SendVerificationEmail: failed to recreate transporter`);
        };
    }
    catch (e) {
        Logger.error(`SendVerificationEmail: exception sending verification email. Acct=${pAccount.id}/${pAccount.username}. e=${e}`);
    }
    return;
}
Example #4
Source File: EmailFactory.ts    From ZenTS with MIT License 5 votes vote down vote up
constructor(protected emailTemplates: EmailTemplates) {
    if (config.email?.enable) {
      this.transporter = createTransport(config.email)
    } else {
      this.transporter = null
    }
  }
Example #5
Source File: create-transport.ts    From server with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Mail Transporter using Node mailer
 *
 * @param {ISMTPProviderDoc} SMTPProvider - SMTP Provider Document from Database
 * @param {ISMTPMailerDoc} SMTPMailer - SMTP Mailer Document from Database
 * @param {IGMAILOptions} gmailOptions - GMAIL Credential Document from Database
 * @returns {Transporter} - Nodemailer Transporter
 */
export default function (
  SMTPProvider: ISMTPProviderDoc,
  SMTPMailer: ISMTPMailerDoc,
  gmailOptions?: IGMAILOptions,
): Transporter {
  const transporterOptions:
    | SMTPPool
    | SMTPPool['options']
    | SMTPTransport
    | SMTPTransport['options'] = {
    host: SMTPProvider.smtp.url,
    port: SMTPProvider.smtp.port,
    pool: true,
    secure: true,
    auth: {
      user: SMTPMailer.email,
      pass: SMTPMailer.password,
    },
  };
  if (SMTPProvider.dkim_key && SMTPProvider.dkim_options) {
    transporterOptions.dkim = {
      privateKey: SMTPProvider.dkim_key,
      domainName: SMTPProvider.dkim_options.domain,
      keySelector: SMTPProvider.dkim_options.key_selector,
    };
  }
  if (SMTPProvider.type === 'gmail' && gmailOptions) {
    if (gmailOptions.type === 'normal') {
      transporterOptions.auth = {
        ...transporterOptions.auth,
        type: 'OAUTH2',
        clientId: gmailOptions.credentials.client_id,
        clientSecret: gmailOptions.credentials.client_secret,
        refreshToken: gmailOptions.tokens.refresh.token,
        accessToken: gmailOptions.tokens.access.token,
        expires: gmailOptions.tokens.access.expires_at,
      };
    } else if (
      gmailOptions.type === 'service' &&
      gmailOptions.service_account
    ) {
      transporterOptions.auth = {
        ...transporterOptions.auth,
        type: 'OAUTH2',
        user: gmailOptions.service_account.client.email,
        serviceClient: gmailOptions.service_account.client.id,
        privateKey: gmailOptions.service_account.private_key.key,
        accessToken: gmailOptions.tokens.access.token,
        expires: gmailOptions.tokens.access.expires_at,
      };
    } else {
      throw new Error(
        'Configuration is Wrong, Please pass Parameters Carefully Again',
      );
    }
  } else if (SMTPProvider.type === 'gmail' && !gmailOptions) {
    throw new Error(
      'GmailOptions is Necessary if SMTP is of Type Gmail, Please pass the Gmailoptions',
    );
  }
  const transporter = createTransport(transporterOptions);
  return transporter;
}