Custom source

If you want to use your own custom generated RFC822 formatted message source, instead of letting Nodemailer to generate it from the message options, use option raw. This can be used both for the entire message or alternatively per-attachment or per-alternative.

Don’t forget to set the envelope option when using raw as the message source

Examples

1. Use string as a message body

This example loads the entire message source from a string value. You don’t have to worry about proper newlines, these are handled by Nodemailer.

let message = {
    envelope: {
        from: '[email protected]',
        to: ['[email protected]']
    },
    raw: `From: [email protected]
To: [email protected]
Subject: test message

Hello world!`
};

2. Set EML file as message body

This example loads the entire message source from a file

let message = {
    envelope: {
        from: '[email protected]',
        to: ['[email protected]']
    },
    raw: {
        path: '/path/to/message.eml'
    }
};

3. Set string as attachment body

When using raw for attachments then you need to provide all content headers youself, Nodemailer does not process it in any way (besides newline processing), it is inserted into the MIME tree as is.

let message = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Custom attachment',
    attachments: [{
        raw: `Content-Type: text/plain
Content-Disposition: attachment

Attached text file`}]
};