nodemailer

  • Version 10.0.14
  • Published
  • 1.58 MB
  • No dependencies
  • MIT-0 license

Install

npm i nodemailer
yarn add nodemailer
pnpm add nodemailer

Overview

Easy as cake e-mail sending from your Node.js applications

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable nodemailer

const nodemailer: {
createTransport: typeof createTransport;
createTestAccount: typeof createTestAccount;
getTestMessageUrl: typeof getTestMessageUrl;
};

    Functions

    function createTestAccount

    createTestAccount: {
    (callback: TestAccountCallback): void;
    (apiUrl: string | false, callback: TestAccountCallback): void;
    (apiUrl?: string | false): Promise<TestAccount>;
    };
    • Creates a test account from the Ethereal service (https://ethereal.email)

      Parameter callback

      Callback function to run with the account object

    • Creates a test account from the Ethereal service (https://ethereal.email)

      Parameter apiUrl

      API endpoint, defaults to https://api.nodemailer.com

      Parameter callback

      Callback function to run with the account object

    • Creates a test account from the Ethereal service (https://ethereal.email)

      Parameter apiUrl

      API endpoint, defaults to https://api.nodemailer.com

      Returns

      Promise that resolves with the account object

    function createTransport

    createTransport: {
    (
    transporter: SMTPPool | (SMTPPoolOptions & { pool: true }),
    defaults?: MailDefaults
    ): Mail<SMTPPoolSentMessageInfo, SMTPPoolOptions>;
    (
    transporter:
    | SendmailTransport
    | (SendmailTransportOptions & { sendmail: string | true }),
    defaults?: SendMailOptions
    ): Mail<SendmailSentMessageInfo, SendmailTransportOptions>;
    (
    transporter:
    | StreamTransport
    | (StreamTransportOptions & { streamTransport: true }),
    defaults?: SendMailOptions
    ): Mail<StreamSentMessageInfo, StreamTransportOptions>;
    (
    transporter: JSONTransportOptions & {
    jsonTransport: true;
    skipEncoding: true;
    },
    defaults?: SendMailOptions
    ): Mail<JSONSentMessageObjectInfo, JSONTransportOptions>;
    (
    transporter:
    | JSONTransport
    | (JSONTransportOptions & { jsonTransport: true }),
    defaults?: SendMailOptions
    ): Mail<JSONSentMessageInfo<string>, JSONTransportOptions>;
    (
    transporter: SESTransport | (SESTransportOptions & { SES: object }),
    defaults?: SendMailOptions
    ): Mail<SESSentMessageInfo, SESTransportOptions>;
    (transporter: SMTPTransport, defaults?: SendMailOptions): Mail<
    SMTPSentMessageInfo,
    SMTPTransportOptions
    >;
    <T = SentMessageInfo, D extends TransportOptions = TransportOptions>(
    transporter: Transport<T, D>,
    defaults?: SendMailOptions
    ): Mail<T, D>;
    (transporter?: string | SMTPTransportOptions, defaults?: SendMailOptions): Mail<
    SMTPSentMessageInfo,
    SMTPTransportOptions
    >;
    (
    transporter?: string | TransportConfig | Transport<any, any>,
    defaults?: SendMailOptions
    ): Mail<any, any>;
    };
    • Creates a transporter object for sending e-mails

      Parameter transporter

      Transport configuration object, a connection URL or a transport plugin instance

      Parameter defaults

      Default message fields that are merged into every message

      Returns

      Mail instance wrapping the transport

    function getTestMessageUrl

    getTestMessageUrl: (
    info?: { response?: string | Buffer | null | undefined } | false | null
    ) => string | false;
    • Resolves the Ethereal web URL for a message sent through an Ethereal test account

      Parameter info

      Result object of sendMail()

      Returns

      URL of the message in the Ethereal web interface, or false if the response does not carry one

    Classes

    class Mail

    class Mail<
    out T = SentMessageInfo,
    out D extends TransportOptions = TransportOptions
    > extends EventEmitter {}
    • Creates an object for exposing the Mail API

      Parameter transporter

      Transport object instance to pass the mails to

    constructor

    constructor(
    transporter: Transport<T, D>,
    options?: TransportOptions,
    defaults?: SendMailOptions
    );

      property close

      close: () => void;
      • Closes the transport, the pooled SMTP transport closes its connections

      property dkim

      dkim: false | DKIM;

        property getSocket

        getSocket?: false | GetSocketHandler;
        • Socket handler for a proxied connection, set by setupProxy and handed to the transport on the next send

        property isIdle

        isIdle: () => boolean;
        • Tells whether the transport can take a message right away

        property logger

        logger: shared.Logger;

          property meta

          meta: Map<string, any>;

            property options

            options: TransportOptions;

              property transporter

              transporter: Transport<T, D>;

                property verify

                verify: { (callback: VerifyCallback): void; (): Promise<true> };
                • Checks the configuration, the SMTP transports connect and authenticate for it

                method get

                get: <K extends string>(key: K) => MailMeta[K] | undefined;

                  method getVersionString

                  getVersionString: () => string;

                    method sendMail

                    sendMail: {
                    (data: SendMailOptions): Promise<T>;
                    (data: SendMailOptions, callback: SendMailCallback<T>): void;
                    };
                    • Sends an email using the preselected transport object

                      Parameter data

                      E-data description

                      Returns

                      Promise that resolves with the result of the send

                    • Sends an email using the preselected transport object

                      Parameter data

                      E-data description

                      Parameter callback

                      Callback to run once the sending succeeded or failed

                    method set

                    set: <K extends string>(key: K, value: MailMeta[K]) => Map<string, any>;

                      method setupProxy

                      setupProxy: (proxyUrl: string) => void;
                      • Sets up proxy handler for a Nodemailer object

                        Parameter proxyUrl

                        Proxy configuration url

                      method use

                      use: (step: string, plugin: PluginFunction<T>) => this;

                        class MailMessage

                        class MailMessage<T = SentMessageInfo> {}

                          constructor

                          constructor(mailer: Mail<T, TransportOptions>, data?: SendMailOptions);

                            property data

                            data: MailMessageData;

                              property mailer

                              mailer: Mail<T, TransportOptions>;

                                property message

                                message: MimeNode;
                                • The compiled MIME tree. Set once the compile step is done, so it is null while the 'compile' plugins run and set by the time the 'stream' plugins and the transport see the message. Declared as always set, the way @types/nodemailer declared it, since the plugins that read it are the ones that run after it is set

                                method normalize

                                normalize: (callback: MailMessageDataCallback) => void;

                                  method resolveAll

                                  resolveAll: (callback: MailMessageDataCallback) => void;

                                    method resolveContent

                                    resolveContent: {
                                    (
                                    data: { [key: string]: any },
                                    key: string | number,
                                    callback: MailMessageContentCallback
                                    ): void;
                                    (
                                    data: { [key: string]: any },
                                    key: string | number,
                                    options: false | ResolveContentOptions,
                                    callback: MailMessageContentCallback
                                    ): void;
                                    (
                                    data: { [key: string]: any },
                                    key: string | number,
                                    options?: false | ResolveContentOptions
                                    ): Promise<any>;
                                    };

                                      method setListHeaders

                                      setListHeaders: () => void;

                                        method setMailerHeader

                                        setMailerHeader: () => void;

                                          method setPriorityHeaders

                                          setPriorityHeaders: () => void;

                                            Interfaces

                                            interface Address

                                            interface MimeNodeAddress {}
                                            • An address object as accepted in address headers and produced by getAddresses. Either a mailbox with an address or a group holding a list of addresses

                                            property address

                                            address?: string | undefined;

                                              property group

                                              group?: MimeNodeAddress[] | undefined;

                                                property name

                                                name?: string | undefined;

                                                  interface Attachment

                                                  interface MailComposerAttachment extends MailComposerAlternative {}
                                                  • An attachment, the shape of the attachments entries

                                                  property cid

                                                  cid?: string | undefined;
                                                  • Content-Id for an embedded image, moves the attachment into the multipart/related node beside the html

                                                  property contentDisposition

                                                  contentDisposition?: string | undefined;
                                                  • Content-Disposition for the node, 'attachment' by default and 'inline' for a message node or an image with a cid

                                                  interface AttachmentLike

                                                  interface MailComposerAlternative {}
                                                  • A content element, the shape of the text, html, watchHtml, amp and alternatives values. The content is either given in content, read from path or href, or raw supplies a pregenerated MIME part

                                                  property content

                                                  content?: MimeNodeContent | undefined;
                                                  • The content itself: a string, a Buffer, a readable stream or a content descriptor

                                                  property contentTransferEncoding

                                                  contentTransferEncoding?: string | false | undefined;
                                                  • Content-Transfer-Encoding for the node, false leaves the choice to the node

                                                  property contentType

                                                  contentType?: string | undefined;
                                                  • Content type, detected from the filename, path or URL when not set

                                                  property encoding

                                                  encoding?: string | undefined;
                                                  • Encoding of a string content, decoded into a Buffer unless it is utf8 or ascii

                                                  property filename

                                                  filename?: string | false | undefined;
                                                  • Filename for the node, false suppresses the generated one

                                                  property headers

                                                  headers?: MimeNodeHeaders | undefined;
                                                  • Additional headers for the node

                                                  property href

                                                  href?: string | false | undefined;
                                                  • URL or data URI to fetch the content from

                                                  property httpHeaders

                                                  httpHeaders?: OutgoingHttpHeaders | undefined;
                                                  • Request headers for a URL fetch

                                                  property path

                                                  path?: string | false | undefined;
                                                  • File path, data URI or http(s) URL to read the content from

                                                  property raw

                                                  raw?: MimeNodeContent | undefined;
                                                  • Pregenerated MIME part, used as is instead of building the node

                                                  property tls

                                                  tls?:
                                                  | {
                                                  [key: string]: any;
                                                  }
                                                  | undefined;
                                                  • TLS settings for a URL fetch, see nmfetch

                                                  interface DKIMOptions

                                                  interface DKIMOptions extends DKIMSignOptions {}
                                                  • Options for the DKIM signer

                                                  property cacheDir

                                                  cacheDir?: string | false | undefined;
                                                  • Directory for buffering large message bodies to disk, no buffering when not set

                                                  property cacheTreshold

                                                  cacheTreshold?: number | undefined;
                                                  • Body size in bytes from which the body is buffered to cacheDir, defaults to 10 MB

                                                  property hashAlgo

                                                  hashAlgo?: string | undefined;
                                                  • Hash algorithm for the body hash and the signature, defaults to sha256

                                                  property keys

                                                  keys?: DKIMKey | DKIMKey[] | undefined;
                                                  • One or more signing keys, used instead of the domainName, keySelector and privateKey options

                                                  interface IcalAttachment

                                                  interface MailComposerIcalEvent extends MailComposerAlternative {}
                                                  • The icalEvent value as an object

                                                  property method

                                                  method?: string | undefined;
                                                  • iCalendar method, PUBLISH by default

                                                  interface JSONSentMessageInfo

                                                  interface JSONSentMessageInfo<M = string> extends SentMessageInfo {}
                                                  • The value the JSON transport hands to the send callback. M is the type of the message field: a JSON string by default, the message object itself when skipEncoding is set

                                                  property envelope

                                                  envelope: MimeNodeEnvelope;
                                                  • The envelope the message was generated with

                                                  property message

                                                  message: M;
                                                  • The normalized message as a JSON string, or as the object itself when skipEncoding is set

                                                  property messageId

                                                  messageId: string;
                                                  • Message-ID value of the message

                                                  interface JSONTransportOptions

                                                  interface JSONTransportOptions extends TransportOptions {}
                                                  • Options for the JSON transport

                                                  property jsonTransport

                                                  jsonTransport?: boolean | undefined;
                                                  • Selects this transport in createTransport

                                                  property skipEncoding

                                                  skipEncoding?: boolean | undefined;
                                                  • If true, the message is returned as an object instead of a JSON string

                                                  interface ListHeaders

                                                  interface MailComposerListHeaders {}
                                                  • The list value: List-* headers keyed by the part after "List-" (help, unsubscribe, subscribe, post, owner, archive, id). An array emits one header per entry, an entry that is itself an array joins its values into one header

                                                  index signature

                                                  [key: string]:
                                                  | MailComposerListHeaderEntry
                                                  | (MailComposerListHeaderEntry | MailComposerListHeaderEntry[])[];

                                                    interface MailComposerOptions

                                                    interface MailComposerOptions {}
                                                    • Mail options, the message data MailComposer builds the MIME tree from. The address fields, subject, messageId, date, inReplyTo and references become headers of the root node. Some fields are read by the mailer that hands the data to MailComposer rather than by MailComposer itself, these are marked as such

                                                    property alternatives

                                                    alternatives?: MailComposerAlternative[] | undefined;
                                                    • Further alternatives for the multipart/alternative node, after text, watchHtml, amp, html and the calendar event

                                                    property amp

                                                    amp?: string | Buffer | Readable | MailComposerAlternative | undefined;
                                                    • AMP4EMAIL version of the message

                                                    property attachDataUrls

                                                    attachDataUrls?: boolean | undefined;
                                                    • Convert data: images in the html into embedded attachments, read by the mailer

                                                    property attachments

                                                    attachments?: MailComposerAttachment[] | undefined;

                                                      property baseBoundary

                                                      baseBoundary?: string | undefined;
                                                      • Shared part of the unique multipart boundary

                                                      property bcc

                                                      bcc?: MimeNodeAddressInput | undefined;

                                                        property boundaryPrefix

                                                        boundaryPrefix?: string | undefined;
                                                        • Prefix for the generated multipart boundaries

                                                        property cc

                                                        cc?: MimeNodeAddressInput | undefined;

                                                          property date

                                                          date?: Date | string | undefined;
                                                          • Date header value, the current time when missing

                                                          property disableFileAccess

                                                          disableFileAccess?: boolean | undefined;
                                                          • Reject content that points to a file path

                                                          property disableUrlAccess

                                                          disableUrlAccess?: boolean | undefined;
                                                          • Reject content that points to a URL

                                                          property encoding

                                                          encoding?: string | undefined;
                                                          • Content-Transfer-Encoding to force for the text/* nodes that do not set their own

                                                          property envelope

                                                          envelope?: MimeNodeEnvelopeInput | undefined;
                                                          • SMTP envelope to use instead of the one generated from the headers

                                                          property from

                                                          from?: MimeNodeAddressInput | undefined;

                                                            property headers

                                                            headers?: MimeNodeHeaders | undefined;
                                                            • Custom headers for the root node, the standard headers above override them

                                                            property html

                                                            html?: string | Buffer | Readable | MailComposerAlternative | undefined;
                                                            • HTML version of the message

                                                            property icalEvent

                                                            icalEvent?: string | Buffer | Readable | MailComposerIcalEvent | undefined;
                                                            • iCalendar event, included both as a text/calendar alternative and as an application/ics attachment

                                                            property inReplyTo

                                                            inReplyTo?: string | undefined;

                                                              property list

                                                              list?: MailComposerListHeaders | undefined;
                                                              • List-* headers, read by the mailer

                                                              property messageId

                                                              messageId?: string | undefined;
                                                              • Message-ID header value, generated when missing

                                                              property newline

                                                              newline?: string | undefined;
                                                              • 'win' for CRLF and 'linux' for LF line breaks in the generated message, kept as is when not set

                                                              property normalizeHeaderKey

                                                              normalizeHeaderKey?: MimeNodeOptions['normalizeHeaderKey'] | undefined;
                                                              • Method to normalize header keys for custom caseing

                                                              property priority

                                                              priority?: string | undefined;
                                                              • 'high', 'normal' or 'low', sets the priority headers, read by the mailer

                                                              property raw

                                                              raw?: MimeNodeContent | undefined;
                                                              • Pregenerated rfc822 message, used as is instead of building one

                                                              property references

                                                              references?: string | string[] | undefined;

                                                                property replyTo

                                                                replyTo?: MimeNodeAddressInput | undefined;

                                                                  property sender

                                                                  sender?: MimeNodeAddressInput | undefined;

                                                                    property subject

                                                                    subject?: string | undefined;

                                                                      property text

                                                                      text?: string | Buffer | Readable | MailComposerAlternative | undefined;
                                                                      • Plaintext version of the message

                                                                      property textEncoding

                                                                      textEncoding?: MailComposerTextEncoding | undefined;
                                                                      • Header string encoding, 'Q' (the default) or 'B', 'quoted-printable' and 'base64' are accepted as well

                                                                      property to

                                                                      to?: MimeNodeAddressInput | undefined;

                                                                        property watchHtml

                                                                        watchHtml?: string | Buffer | Readable | MailComposerAlternative | undefined;
                                                                        • Apple Watch specific HTML version of the message

                                                                        property xMailer

                                                                        xMailer?: string | false | undefined;
                                                                        • X-Mailer header value, false leaves the header out, read by the mailer

                                                                        interface MailMessageData

                                                                        interface MailMessageData extends SendMailOptions {}
                                                                        • The message data as held by a MailMessage: the options the caller passed to sendMail with the transporter defaults applied. resolveAll rewrites the content and address fields in place and normalize adds the envelope, the Message-ID and the normalized headers

                                                                        property normalizedHeaders

                                                                        normalizedHeaders?:
                                                                        | {
                                                                        [key: string]: string;
                                                                        }
                                                                        | undefined;
                                                                        • Header values flattened to strings and keyed by lowercase header name, set by normalize

                                                                        interface NodemailerError

                                                                        interface NodemailerError extends NodeJS.ErrnoException {}
                                                                        • An Error together with the properties Nodemailer attaches to the errors it hands to callers. Every property is optional, the set that is present depends on where the error originated. Socket level errors keep the errno and syscall fields Node.js sets on them.

                                                                        property code

                                                                        code?: string | undefined;
                                                                        • Nodemailer error code, see ERROR_CODES

                                                                        property command

                                                                        command?: string | undefined;
                                                                        • SMTP command that was in flight when the server replied with an error

                                                                        property recipient

                                                                        recipient?: string | undefined;
                                                                        • Recipient address the error applies to

                                                                        property rejected

                                                                        rejected?: string[] | undefined;
                                                                        • Recipient addresses rejected by the server

                                                                        property rejectedErrors

                                                                        rejectedErrors?: NodemailerError[] | undefined;
                                                                        • Per-recipient errors for the rejected addresses

                                                                        property response

                                                                        response?: string | undefined;
                                                                        • Raw SMTP server response

                                                                        property responseCode

                                                                        responseCode?: number | undefined;
                                                                        • Numeric SMTP response code

                                                                        property sourceUrl

                                                                        sourceUrl?: string | undefined;
                                                                        • URL of the resource that could not be fetched

                                                                        interface SendMailOptions

                                                                        interface SendMailOptions extends MailComposerOptions {}
                                                                        • The message data accepted by sendMail. MailComposerOptions describes the fields the MIME tree is built from, the fields below are the ones the mailer reads on top of those

                                                                        property auth

                                                                        auth?: SMTPTransportAuthOptions | undefined;
                                                                        • SMTP transports: per-message authentication settings, used instead of the transport level auth

                                                                        property dkim

                                                                        dkim?: DKIMOptions | undefined;
                                                                        • DKIM signing options for this message, used instead of the ones of the transporter

                                                                        property dsn

                                                                        dsn?: SMTPEnvelopeDsn | undefined;
                                                                        • SMTP transports: DSN parameters for the envelope, sent when the server supports the DSN extension

                                                                        property maxRecipients

                                                                        maxRecipients?: number | undefined;
                                                                        • Recipients allowed on this message, 0 disables the limit, defaults to 100000

                                                                        property requireTLSExtensionEnabled

                                                                        requireTLSExtensionEnabled?: boolean | undefined;
                                                                        • SMTP transports: RFC 8689, send the REQUIRETLS parameter with MAIL FROM

                                                                        property ses

                                                                        ses?: SESSendEmailRequest | undefined;
                                                                        • SES transport: extra SendEmailCommand parameters merged into the API call

                                                                        interface SendmailSentMessageInfo

                                                                        interface SendmailSentMessageInfo extends SentMessageInfo {}
                                                                        • The value the Sendmail transport hands to the send callback

                                                                        property envelope

                                                                        envelope: MimeNodeEnvelope;
                                                                        • The envelope the message was sent with

                                                                        property messageId

                                                                        messageId: string;
                                                                        • Message-ID value of the message

                                                                        property response

                                                                        response: string;
                                                                        • Always 'Messages queued for delivery'

                                                                        interface SendmailTransportOptions

                                                                        interface SendmailTransportOptions extends TransportOptions {}
                                                                        • Options for the Sendmail transport

                                                                        property args

                                                                        args?: string[] | undefined;
                                                                        • Arguments for the sendmail binary, replaces the default '-f '

                                                                        property newline

                                                                        newline?: string | undefined;
                                                                        • Either 'windows' or 'unix', the line ending of the message piped to sendmail

                                                                        property path

                                                                        path?: string | undefined;
                                                                        • Path to the sendmail binary, defaults to 'sendmail'

                                                                        property sendmail

                                                                        sendmail?: boolean | string | undefined;
                                                                        • Selects this transport in createTransport, the binary itself is set with path

                                                                        interface SentMessageInfo

                                                                        interface SentMessageInfo {}
                                                                        • The base shape of the object a transport hands back for a sent message. Every bundled transport sets the envelope and the Message-ID, the rest depends on the transport.

                                                                          The index signature keeps a transport specific field readable through this type, the way the any typed result of @types/nodemailer was, and it is also what a result type has to inherit to stay assignable to it, so the result type of a transport outside this package has to extend this interface rather than restate it

                                                                        property accepted

                                                                        accepted?: string[] | undefined;
                                                                        • Recipient addresses the transport accepted

                                                                        property envelope

                                                                        envelope: MimeNodeEnvelope;
                                                                        • The envelope the message was sent with

                                                                        property message

                                                                        message?: any;
                                                                        • The generated message, for the transports that hand it back instead of sending it

                                                                        property messageId

                                                                        messageId: string;
                                                                        • Message-ID of the sent message

                                                                        property pending

                                                                        pending?: string[] | undefined;
                                                                        • Recipient addresses left pending, LMTP reports these

                                                                        property rejected

                                                                        rejected?: string[] | undefined;
                                                                        • Recipient addresses the transport rejected

                                                                        property response

                                                                        response?: string | undefined;
                                                                        • Last response from the server

                                                                        index signature

                                                                        [key: string]: any;
                                                                        • Transport specific fields

                                                                        interface SESSentMessageInfo

                                                                        interface SESSentMessageInfo extends SentMessageInfo {}
                                                                        • The value the SES transport hands to the send callback

                                                                        property envelope

                                                                        envelope: MimeNodeEnvelope;
                                                                        • The envelope the message was sent with

                                                                        property messageId

                                                                        messageId: string;
                                                                        • Message-ID built from the MessageId SES returned

                                                                        property raw

                                                                        raw: Buffer;
                                                                        • The raw RFC822 message that was sent

                                                                        property response

                                                                        response: string;
                                                                        • The MessageId SES returned

                                                                        interface SESTransportOptions

                                                                        interface SESTransportOptions extends TransportOptions {}
                                                                        • Options for the SES transport

                                                                        property SES

                                                                        SES: {
                                                                        /** SESv2Client instance. Its config.region provider is resolved for the domain of the returned Message-ID */
                                                                        sesClient: {
                                                                        config?:
                                                                        | {
                                                                        region?: (() => Promise<string>) | undefined;
                                                                        [key: string]: any;
                                                                        }
                                                                        | undefined;
                                                                        send(command: unknown): Promise<any>;
                                                                        };
                                                                        /** SendEmailCommand class, constructed with the SendEmailCommandInput of every message */
                                                                        SendEmailCommand: new (input: any) => unknown;
                                                                        };
                                                                        • The AWS SDK v3 objects to send with, { sesClient, SendEmailCommand } from @aws-sdk/client-sesv2

                                                                        interface SMTPConnectionAuth

                                                                        interface SMTPConnectionAuth {}
                                                                        • Authentication data for login()

                                                                        property credentials

                                                                        credentials?: SMTPConnectionCredentials | undefined;
                                                                        • Credentials for the SASL mechanism, filled in from user and pass when missing

                                                                        property method

                                                                        method?: string | false | undefined;
                                                                        • SASL method to use, false or unset picks the first supported one (PLAIN if none is advertised)

                                                                        property oauth2

                                                                        oauth2?: XOAuth2 | undefined;
                                                                        • XOAuth2 token generator, selects XOAUTH2 when no method is set

                                                                        property options

                                                                        options?:
                                                                        | {
                                                                        [key: string]: any;
                                                                        }
                                                                        | undefined;
                                                                        • Extra options for the authentication method

                                                                        property pass

                                                                        pass?: string | undefined;

                                                                          property type

                                                                          type?: string | undefined;
                                                                          • Authentication type, informational

                                                                          property user

                                                                          user?: string | undefined;

                                                                            index signature

                                                                            [key: string]: any;
                                                                            • Custom authentication handlers receive the auth object as is, so it may carry any other value

                                                                            interface SMTPConnectionOptions

                                                                            interface SMTPConnectionOptions {}
                                                                            • Options for the SMTP connection, see the SMTPConnection class description

                                                                            property allowInternalNetworkInterfaces

                                                                            allowInternalNetworkInterfaces?: boolean | undefined;
                                                                            • Count loopback interfaces when checking which address families are usable

                                                                            property component

                                                                            component?: string | undefined;
                                                                            • Logger component name, defaults to 'smtp-connection'

                                                                            property connection

                                                                            connection?: net.Socket | undefined;
                                                                            • Already opened connection to use instead of creating a new one

                                                                            property connectionTimeout

                                                                            connectionTimeout?: number | undefined;
                                                                            • Time to wait in ms for the connection to establish, defaults to 2 minutes

                                                                            property customAuth

                                                                            customAuth?: SMTPConnectionCustomAuthHandlers | undefined;
                                                                            • Custom authentication handlers keyed by method name

                                                                            property debug

                                                                            debug?: boolean | undefined;
                                                                            • Pass SMTP traffic, including the message data, to the logger

                                                                            property dnsTimeout

                                                                            dnsTimeout?: number | undefined;
                                                                            • Time to wait in ms for the DNS requests to be resolved, defaults to 30 seconds

                                                                            property greetingTimeout

                                                                            greetingTimeout?: number | undefined;
                                                                            • Time to wait in ms until the greeting is received, defaults to 30 seconds

                                                                            property host

                                                                            host?: string | undefined;
                                                                            • Hostname or IP address to connect to, defaults to 'localhost'

                                                                            property ignoreTLS

                                                                            ignoreTLS?: boolean | undefined;
                                                                            • Ignore STARTTLS even when the server advertises it, has no effect when requireTLS is set

                                                                            property lmtp

                                                                            lmtp?: boolean | undefined;
                                                                            • Use LMTP instead of SMTP

                                                                            property localAddress

                                                                            localAddress?: string | undefined;
                                                                            • Outbound address to bind to

                                                                            property logger

                                                                            logger?: shared.ExternalLogger | boolean | undefined;
                                                                            • Bunyan compatible logger interface, true for the default console logger

                                                                            property maxResponseSize

                                                                            maxResponseSize?: number | undefined;
                                                                            • Largest single server response to accept in bytes, defaults to 1 MB

                                                                            property name

                                                                            name?: string | undefined;
                                                                            • Name of the client server, sent with EHLO/HELO, CRLF is stripped

                                                                            property opportunisticTLS

                                                                            opportunisticTLS?: boolean | undefined;
                                                                            • Continue unencrypted when the STARTTLS upgrade fails, has no effect when requireTLS is set

                                                                            property port

                                                                            port?: number | string | undefined;
                                                                            • Port to connect to, defaults to 587, or to 465 when secure is set

                                                                            property requireTLS

                                                                            requireTLS?: boolean | undefined;
                                                                            • Force STARTTLS, fail when the server does not support it. Takes precedence over ignoreTLS and opportunisticTLS

                                                                            property secure

                                                                            secure?: boolean | undefined;
                                                                            • Use TLS from the start

                                                                            property secured

                                                                            secured?: boolean | undefined;
                                                                            • Marks the provided socket as already upgraded to TLS

                                                                            property servername

                                                                            servername?: string | undefined;
                                                                            • Server name for SNI, defaults to host when that is not an IP address

                                                                            property socket

                                                                            socket?: net.Socket | undefined;
                                                                            • Existing socket to use instead of creating a new one, not connected yet

                                                                            property socketTimeout

                                                                            socketTimeout?: number | undefined;
                                                                            • Time of inactivity in ms until the connection is closed, defaults to 10 minutes

                                                                            property tls

                                                                            tls?: tls.ConnectionOptions | undefined;
                                                                            • Options for tls.connect

                                                                            property transactionLog

                                                                            transactionLog?: boolean | undefined;
                                                                            • Pass SMTP commands and responses to the logger

                                                                            interface SMTPEnvelope

                                                                            interface SMTPEnvelope {}
                                                                            • Envelope object accepted by send()

                                                                            property dsn

                                                                            dsn?: SMTPEnvelopeDsn | undefined;
                                                                            • DSN parameters, sent when the server supports the DSN extension

                                                                            property from

                                                                            from?: string | SMTPEnvelopeAddress | false | undefined;
                                                                            • Sender address, false for the null sender of a bounce message (MAIL FROM:<>)

                                                                            property requireTLSExtensionEnabled

                                                                            requireTLSExtensionEnabled?: boolean | undefined;
                                                                            • RFC 8689: send the REQUIRETLS parameter, requires a TLS connection and server support

                                                                            property size

                                                                            size?: number | string | undefined;
                                                                            • Message size in bytes, sent as the SIZE parameter when the server supports it

                                                                            property to

                                                                            to?:
                                                                            | string
                                                                            | SMTPEnvelopeAddress
                                                                            | Array<string | SMTPEnvelopeAddress>
                                                                            | undefined;
                                                                            • Recipient address or addresses

                                                                            property use8BitMime

                                                                            use8BitMime?: boolean | undefined;
                                                                            • Declare BODY=8BITMIME when the server supports it

                                                                            interface SMTPEnvelopeDsn

                                                                            interface SMTPEnvelopeDsn {}
                                                                            • DSN parameters for the envelope (RFC 3461)

                                                                            property envid

                                                                            envid?: string | null | undefined;
                                                                            • Envelope identifier, sent as ENVID

                                                                            property id

                                                                            id?: string | undefined;
                                                                            • Alias of envid

                                                                            property notify

                                                                            notify?: string | string[] | null | undefined;
                                                                            • When to notify: 'NEVER', or any combination of 'SUCCESS', 'FAILURE' and 'DELAY'

                                                                            property orcpt

                                                                            orcpt?: string | null | undefined;
                                                                            • Alias of recipient, in the 'rfc822;address' form

                                                                            property recipient

                                                                            recipient?: string | undefined;
                                                                            • Original recipient, sent as ORCPT

                                                                            property ret

                                                                            ret?: string | null | undefined;
                                                                            • Return either 'HDRS' (headers) or 'FULL' (body) with the notification

                                                                            property return

                                                                            return?: string | undefined;
                                                                            • Alias of ret

                                                                            interface SMTPPoolOptions

                                                                            interface SMTPPoolOptions extends SMTPTransportOptions {}
                                                                            • Options for the pooled SMTP transport, the SMTP transport options plus the pool settings

                                                                            property maxConnections

                                                                            maxConnections?: number | undefined;
                                                                            • Maximum number of open connections, defaults to 5

                                                                            property maxMessages

                                                                            maxMessages?: number | undefined;
                                                                            • Number of messages a connection sends before it is closed and replaced, defaults to 100

                                                                            property maxRequeues

                                                                            maxRequeues?: number | undefined;
                                                                            • How many times a message is requeued when its connection closes while sending, defaults to 5, a negative value means unlimited

                                                                            property pool

                                                                            pool?: boolean | undefined;
                                                                            • Set to true to get this pooled transport from createTransport

                                                                            property rateDelta

                                                                            rateDelta?: number | undefined;
                                                                            • Time window for rateLimit in milliseconds, defaults to 1000

                                                                            property rateLimit

                                                                            rateLimit?: number | undefined;
                                                                            • Maximum number of messages to send in rateDelta milliseconds, unlimited when not set

                                                                            interface SMTPSentMessageInfo

                                                                            interface SMTPSentMessageInfo extends SMTPConnectionSendInfo, SentMessageInfo {}
                                                                            • Result of a sent message, the connection result plus the envelope and the Message-ID

                                                                            property accepted

                                                                            accepted: string[];
                                                                            • Recipients the server accepted

                                                                            property envelope

                                                                            envelope: MimeNodeEnvelope;
                                                                            • Envelope the message was sent with

                                                                            property messageId

                                                                            messageId: string;
                                                                            • Message-ID value of the sent message

                                                                            property rejected

                                                                            rejected: string[];
                                                                            • Recipients the server rejected

                                                                            property response

                                                                            response: string;
                                                                            • Final server response for the message

                                                                            interface SMTPTransportOptions

                                                                            interface SMTPTransportOptions extends SMTPConnectionOptions, TransportOptions {}
                                                                            • Options for the SMTP transport, the connection options plus the transport level settings

                                                                            property auth

                                                                            auth?: SMTPTransportAuthOptions | undefined;
                                                                            • Authentication settings, no authentication when not set

                                                                            property authMethod

                                                                            authMethod?: string | undefined;
                                                                            • Default SASL method for the password logins when the auth settings do not name one

                                                                            property component

                                                                            component?: string | undefined;
                                                                            • Logger component name, defaults to 'smtp-transport'

                                                                            property forceAuth

                                                                            forceAuth?: boolean | undefined;
                                                                            • Authenticate even when the server does not advertise AUTH, and fail verify() when it does but no credentials were given

                                                                            property getSocket

                                                                            getSocket?: SMTPTransportGetSocket | undefined;
                                                                            • Custom socket provider, e.g. for connecting through a proxy, replaces the getSocket method

                                                                            property pool

                                                                            pool?: boolean | undefined;
                                                                            • Set to true to get a pooled transport from createTransport, this transport does not read it

                                                                            property service

                                                                            service?: string | undefined;
                                                                            • Well-known service name, e.g. 'Gmail', fills in host, port and secure

                                                                            property url

                                                                            url?: string | undefined;
                                                                            • Connection url, e.g. 'smtps://user:pass@smtp.example.com', parsed into options

                                                                            interface StreamSentMessageInfo

                                                                            interface StreamSentMessageInfo extends SentMessageInfo {}
                                                                            • The value the Stream transport hands to the send callback

                                                                            property envelope

                                                                            envelope: MimeNodeEnvelope;
                                                                            • The envelope the message was generated with

                                                                            property message

                                                                            message: Readable | Buffer;
                                                                            • The generated message, a Buffer when the buffer option is set, a readable stream otherwise

                                                                            property messageId

                                                                            messageId: string;
                                                                            • Message-ID value of the message

                                                                            interface StreamTransportOptions

                                                                            interface StreamTransportOptions extends TransportOptions {}
                                                                            • Options for the Stream transport

                                                                            property buffer

                                                                            buffer?: boolean | undefined;
                                                                            • If true, the message is returned as a Buffer object instead of a stream

                                                                            property newline

                                                                            newline?: string | undefined;
                                                                            • Either 'windows' or 'unix', the line ending of the generated message

                                                                            property streamTransport

                                                                            streamTransport?: boolean | undefined;
                                                                            • Selects this transport in createTransport

                                                                            interface TestAccount

                                                                            interface TestAccount {}
                                                                            • Ethereal test account returned by createTestAccount()

                                                                            property imap

                                                                            imap: TestAccountService;

                                                                              property mxEnabled

                                                                              mxEnabled?: boolean | undefined;
                                                                              • true if the account can also receive external mail

                                                                              property pass

                                                                              pass: string;

                                                                                property pop3

                                                                                pop3: TestAccountService;

                                                                                  property smtp

                                                                                  smtp: TestAccountService;

                                                                                    property user

                                                                                    user: string;

                                                                                      property web

                                                                                      web: string;

                                                                                        index signature

                                                                                        [key: string]: unknown;

                                                                                          interface TestAccountService

                                                                                          interface TestAccountService {}
                                                                                          • Connection details of a service endpoint of an Ethereal test account

                                                                                          property host

                                                                                          host: string;

                                                                                            property port

                                                                                            port: number;

                                                                                              property secure

                                                                                              secure: boolean;

                                                                                                interface Transport

                                                                                                interface Transport<
                                                                                                T = SentMessageInfo,
                                                                                                D extends TransportOptions = TransportOptions
                                                                                                > {}
                                                                                                • A transport as consumed by Mail: any object with a name, a version and a send method works, the rest is optional. Mail forwards its close, isIdle and verify calls to the methods of the same name as they are, so their arguments are up to the transport.

                                                                                                  D is the options type of the transport, the second type parameter @types/nodemailer declared on Transport, Transporter and Mail

                                                                                                property getSocket

                                                                                                getSocket?: GetSocketHandler | undefined;
                                                                                                • Socket handler for a proxied connection, set by Mail when a proxy is configured

                                                                                                property mailer

                                                                                                mailer?: Mail<T, D> | undefined;
                                                                                                • The Mail object the transport belongs to, set by Mail

                                                                                                property name

                                                                                                name: string;
                                                                                                • Transport name, used for logging

                                                                                                property version

                                                                                                version: string;
                                                                                                • Transport version, used for logging

                                                                                                method close

                                                                                                close: (...args: any[]) => any;
                                                                                                • Closes the transport

                                                                                                method isIdle

                                                                                                isIdle: (...args: any[]) => any;
                                                                                                • Tells whether the transport can take a message right away

                                                                                                method on

                                                                                                on: (event: string | symbol, listener: (...args: any[]) => void) => this;
                                                                                                • Registers an event listener, the transport may emit 'log', 'error', 'idle' and 'clear'

                                                                                                method send

                                                                                                send: (mail: MailMessage<T>, callback: ResultCallback<T>) => void;
                                                                                                • Hands a message to the transport, the callback receives the transport result

                                                                                                method verify

                                                                                                verify: (...args: any[]) => any;
                                                                                                • Checks the configuration, the SMTP transports connect and authenticate for it

                                                                                                interface TransportOptions

                                                                                                interface TransportOptions {}
                                                                                                • Transport configuration as read by Mail itself. The transport reads its own options from the same object, see the transport for those

                                                                                                property attachDataUrls

                                                                                                attachDataUrls?: boolean | undefined;
                                                                                                • Convert data: images in the html into embedded attachments

                                                                                                property component

                                                                                                component?: string | undefined;
                                                                                                • Component name for the log lines, defaults to 'mail'

                                                                                                property disableFileAccess

                                                                                                disableFileAccess?: boolean | undefined;
                                                                                                • Reject content that points to a file path, forced onto every message

                                                                                                property disableUrlAccess

                                                                                                disableUrlAccess?: boolean | undefined;
                                                                                                • Reject content that points to a URL, forced onto every message

                                                                                                property dkim

                                                                                                dkim?: DKIMOptions | undefined;
                                                                                                • DKIM signing options, every message is signed with these unless it carries its own

                                                                                                property logger

                                                                                                logger?: shared.ExternalLogger | boolean | undefined;
                                                                                                • Bunyan compatible logger, true for the default console logger, false or unset for no logging

                                                                                                property maxRecipients

                                                                                                maxRecipients?: number | undefined;
                                                                                                • Recipients allowed on one message, forced onto every message, 0 disables the limit, defaults to 100000

                                                                                                property normalizeHeaderKey

                                                                                                normalizeHeaderKey?: MimeNodeOptions['normalizeHeaderKey'] | undefined;
                                                                                                • Method to normalize header keys for custom caseing, forced onto every message

                                                                                                property proxy

                                                                                                proxy?: string | undefined;
                                                                                                • Proxy url. http(s) proxies work as is, socks proxies need the socks module set with set('proxy_socks_module', socks)

                                                                                                property tls

                                                                                                tls?: ConnectionOptions | undefined;
                                                                                                • TLS options, rejectUnauthorized applies to an https proxy as well

                                                                                                interface XOAuth2Options

                                                                                                interface XOAuth2Options {}
                                                                                                • Client information for token generation

                                                                                                property accessToken

                                                                                                accessToken?: string | undefined;
                                                                                                • An existing valid accessToken

                                                                                                property accessUrl

                                                                                                accessUrl?: string | undefined;
                                                                                                • Endpoint for token generation, defaults to 'https://accounts.google.com/o/oauth2/token'

                                                                                                property clientId

                                                                                                clientId?: string | undefined;
                                                                                                • Client ID value

                                                                                                property clientSecret

                                                                                                clientSecret?: string | undefined;
                                                                                                • Client secret value

                                                                                                property component

                                                                                                component?: string | undefined;
                                                                                                • Logger component name, defaults to 'OAuth2'

                                                                                                property customHeaders

                                                                                                customHeaders?: OutgoingHttpHeaders | undefined;
                                                                                                • Extra headers for the token request

                                                                                                property customParams

                                                                                                customParams?:
                                                                                                | {
                                                                                                [key: string]: any;
                                                                                                }
                                                                                                | undefined;
                                                                                                • Extra form fields for the token request

                                                                                                property expires

                                                                                                expires?: number | undefined;
                                                                                                • Optional Access Token expire time in ms

                                                                                                property privateKey

                                                                                                privateKey?: XOAuth2PrivateKey | undefined;
                                                                                                • Private key for JSW

                                                                                                property provisionCallback

                                                                                                provisionCallback?: XOAuth2ProvisionCallback | undefined;
                                                                                                • Function to run when a new access token is required

                                                                                                property refreshToken

                                                                                                refreshToken?: string | undefined;
                                                                                                • Refresh token for an user

                                                                                                property requestTimeout

                                                                                                requestTimeout?: number | undefined;
                                                                                                • Timeout for the token request in milliseconds, defaults to 60000, 0 disables it

                                                                                                property scope

                                                                                                scope?: string | undefined;
                                                                                                • OAuth2 scope for the service account flow, defaults to 'https://mail.google.com/'

                                                                                                property serviceClient

                                                                                                serviceClient?: string | undefined;
                                                                                                • Service account client id (the JWT issuer), switches to the JWT bearer flow

                                                                                                property serviceRequestTimeout

                                                                                                serviceRequestTimeout?: number | undefined;
                                                                                                • Lifetime of the service account JWT in seconds, defaults to 5 minutes, capped at an hour

                                                                                                property timeout

                                                                                                timeout?: number | undefined;
                                                                                                • Optional TTL for Access Token in seconds

                                                                                                property tls

                                                                                                tls?:
                                                                                                | {
                                                                                                [key: string]: any;
                                                                                                }
                                                                                                | undefined;
                                                                                                • Optional TLS options forwarded to the HTTPS token request. Defaults to strict cert validation; supply { rejectUnauthorized: false } only for self-hosted OAuth providers on private CAs.

                                                                                                property user

                                                                                                user?: string | undefined;
                                                                                                • User e-mail address

                                                                                                interface XOAuth2Token

                                                                                                interface XOAuth2Token {}
                                                                                                • The object emitted with the 'token' event once a new access token has been generated

                                                                                                property accessToken

                                                                                                accessToken: string;
                                                                                                • The new access token

                                                                                                property expires

                                                                                                expires: number;
                                                                                                • Expire time as a timestamp in milliseconds, 0 when unknown

                                                                                                property user

                                                                                                user?: string | undefined;
                                                                                                • User e-mail address

                                                                                                Type Aliases

                                                                                                type ErrorCode

                                                                                                type ErrorCode = keyof typeof ERROR_CODES;
                                                                                                • Union of all known Nodemailer error codes

                                                                                                type Headers

                                                                                                type MimeNodeHeaders = MimeNodeHeader | MimeNodeHeader[] | MimeNodeHeaderMap;
                                                                                                • Several headers at once, as accepted by setHeader and addHeader: a single {key, value} pair, a list of them, or an object keyed by header name

                                                                                                type JSONSentMessageObjectInfo

                                                                                                type JSONSentMessageObjectInfo = JSONSentMessageInfo<any>;
                                                                                                • The value the JSON transport hands to the send callback when skipEncoding is set: the message field holds the message object. Typed loosely so that a transporter created with skipEncoding still fits a variable declared with the plain result type

                                                                                                type MailDefaults

                                                                                                type MailDefaults = SendMailOptions;
                                                                                                • Default message fields, the third argument of createTransport. Applied to every message for the fields the message does not set itself, the headers are merged one by one

                                                                                                type PluginFunction

                                                                                                type PluginFunction<T = SentMessageInfo> = (
                                                                                                mail: MailMessage<T>,
                                                                                                callback: PluginCallback
                                                                                                ) => void;
                                                                                                • A plugin registered with use(): receives the message and a callback to call once done

                                                                                                type SMTPPoolSentMessageInfo

                                                                                                type SMTPPoolSentMessageInfo = SMTPSentMessageInfo;
                                                                                                • Result of a message sent through the pool, same as for the SMTP transport

                                                                                                type TestAccountCallback

                                                                                                type TestAccountCallback = (err: Error | null, account: TestAccount) => void;
                                                                                                • Callback for createTestAccount()

                                                                                                type TransportConfig

                                                                                                type TransportConfig =
                                                                                                | SMTPTransportOptions
                                                                                                | SMTPPoolOptions
                                                                                                | SendmailTransportOptions
                                                                                                | StreamTransportOptions
                                                                                                | JSONTransportOptions
                                                                                                | SESTransportOptions;
                                                                                                • Configuration object of any of the bundled transports

                                                                                                type Transporter

                                                                                                type Transporter<
                                                                                                T = SentMessageInfo,
                                                                                                D extends TransportOptions = TransportOptions
                                                                                                > = Mail<T, D>;
                                                                                                • The transporter object createTransport returns, a Mail instance wrapping a transport. D is the options type of the transport, it types the options field of the transporter

                                                                                                type VerifyCallback

                                                                                                type VerifyCallback = Callback<true>;
                                                                                                • Callback for verify(), success is true once the transport accepted the configuration. Declared with a required success value, the way @types/nodemailer declared it, the error path hands over the error alone

                                                                                                Namespaces

                                                                                                namespace Mail

                                                                                                namespace Mail {}

                                                                                                  type Address

                                                                                                  type Address = MimeNodeAddress;

                                                                                                    type AmpAttachment

                                                                                                    type AmpAttachment = MailComposerAlternative;

                                                                                                      type Attachment

                                                                                                      type Attachment = MailComposerAttachment;

                                                                                                        type AttachmentLike

                                                                                                        type AttachmentLike = MailComposerAlternative;

                                                                                                          type Connection

                                                                                                          type Connection = SocketOptions;

                                                                                                            type Envelope

                                                                                                            type Envelope = MimeNodeEnvelopeInput;

                                                                                                              type Headers

                                                                                                              type Headers = MimeNodeHeaders;

                                                                                                                type IcalAttachment

                                                                                                                type IcalAttachment = MailComposerIcalEvent;

                                                                                                                  type ListHeader

                                                                                                                  type ListHeader = MailComposerListHeaderEntry;

                                                                                                                    type ListHeaders

                                                                                                                    type ListHeaders = MailComposerListHeaders;

                                                                                                                      type Options

                                                                                                                      type Options = SendMailOptions;

                                                                                                                        type PluginFunction

                                                                                                                        type PluginFunction<T = SentMessageInfo> = MailPluginFunction<T>;

                                                                                                                          type TextEncoding

                                                                                                                          type TextEncoding = MailComposerTextEncoding;

                                                                                                                            Package Files (15)

                                                                                                                            Dependencies (0)

                                                                                                                            No dependencies.

                                                                                                                            Dev Dependencies (18)

                                                                                                                            Peer Dependencies (0)

                                                                                                                            No peer dependencies.

                                                                                                                            Badge

                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/nodemailer.

                                                                                                                            • Markdown
                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/nodemailer)
                                                                                                                            • HTML
                                                                                                                              <a href="https://www.jsdocs.io/package/nodemailer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>