Skip to content

Instantly share code, notes, and snippets.

@andris9
Last active November 3, 2020 23:58
Show Gist options
  • Save andris9/3df2d3111b1de4e5a0a51dcbb345210f to your computer and use it in GitHub Desktop.
Save andris9/3df2d3111b1de4e5a0a51dcbb345210f to your computer and use it in GitHub Desktop.
O365 Nodemailer
/* eslint no-console: 0 */
'use strict';
const nodemailer = require('nodemailer');
// Create a SMTP transporter object
let transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
auth: {
user: '[email protected]',
pass: 'password',
},
logger: true,
debug: true, // include SMTP traffic in the logs
});
// Message object
let message = {
from: 'Andris Reinman <[email protected]>',
to: 'Andris Reinman <[email protected]>',
subject: 'O365 test message',
text: 'O365 test message',
};
transporter.sendMail(message, (error, info) => {
if (error) {
console.log('Error occurred');
console.log(error.message);
return process.exit(1);
}
console.log('Message sent successfully!');
console.log(info);
});
[2020-05-28 07:14:24] DEBUG Creating transport: nodemailer (6.4.6; +https://nodemailer.com/; SMTP/6.4.6[client:6.4.6])
[2020-05-28 07:14:24] DEBUG Sending mail using SMTP/6.4.6[client:6.4.6]
[2020-05-28 07:14:24] DEBUG [P7xvpVEEM] Resolved smtp.office365.com as 40.101.126.194 [cache miss]
[2020-05-28 07:14:24] INFO [P7xvpVEEM] Connection established to 40.101.126.194:587
[2020-05-28 07:14:24] DEBUG [P7xvpVEEM] S: 220 HE1P190CA0042.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 28 May 2020 07:14:24 +0000
[2020-05-28 07:14:24] DEBUG [P7xvpVEEM] C: EHLO [127.0.0.1]
[2020-05-28 07:14:24] DEBUG [P7xvpVEEM] S: 250-HE1P190CA0042.outlook.office365.com Hello [90.191.155.125]
[2020-05-28 07:14:24] DEBUG [P7xvpVEEM] S: 250-SIZE 157286400
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-PIPELINING
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-DSN
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-ENHANCEDSTATUSCODES
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-STARTTLS
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-8BITMIME
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-BINARYMIME
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-CHUNKING
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250 SMTPUTF8
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: STARTTLS
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 220 2.0.0 SMTP server ready
[2020-05-28 07:14:25] INFO [P7xvpVEEM] Connection upgraded with STARTTLS
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: EHLO [127.0.0.1]
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-HE1P190CA0042.outlook.office365.com Hello [90.191.155.125]
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-SIZE 157286400
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-PIPELINING
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-DSN
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-ENHANCEDSTATUSCODES
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-AUTH LOGIN XOAUTH2
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-8BITMIME
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-BINARYMIME
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250-CHUNKING
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250 SMTPUTF8
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] SMTP handshake finished
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: AUTH LOGIN
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 334 VXNlcm5hbWU6
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: <base64:[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 334 UGFzc3dvcmQ6
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: <base64:password>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 235 2.7.0 Authentication successful
[2020-05-28 07:14:25] INFO [P7xvpVEEM] User "[email protected]" authenticated
[2020-05-28 07:14:25] INFO Sending message <[email protected]> to <[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: MAIL FROM:<[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250 2.1.0 Sender OK
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: RCPT TO:<[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 250 2.1.5 Recipient OK
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] C: DATA
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] S: 354 Start mail input; end with <CRLF>.<CRLF>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] Content-Type: text/plain
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] From: Andris Reinman <[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] To: Andris Reinman <[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] Subject: O365 test message
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] Message-ID: <[email protected]>
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] Content-Transfer-Encoding: 7bit
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] Date: Thu, 28 May 2020 07:14:24 +0000
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] MIME-Version: 1.0
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM]
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] O365 test message
[2020-05-28 07:14:25] DEBUG [P7xvpVEEM] .
[2020-05-28 07:14:25] INFO [P7xvpVEEM] <324 bytes encoded mime message (source size 321 bytes)>
[2020-05-28 07:14:26] DEBUG [P7xvpVEEM] S: 250 2.0.0 OK <[email protected]> [Hostname=HE1PR03MB3116.eurprd03.prod.outlook.com]
[2020-05-28 07:14:26] DEBUG [P7xvpVEEM] Closing connection to the server using "end"
Message sent successfully!
{
accepted: [ '[email protected]' ],
rejected: [],
envelopeTime: 52,
messageTime: 451,
messageSize: 324,
response: '250 2.0.0 OK <[email protected]> [Hostname=HE1PR03MB3116.eurprd03.prod.outlook.com]',
envelope: { from: '[email protected]', to: [ '[email protected]' ] },
messageId: '<[email protected]>'
}
[2020-05-28 07:14:26] INFO [P7xvpVEEM] Connection closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment