url: 'smtp://{host}:{port}'
but I get a TLS upgrade: https://runkit.com/mathieug/nodemailer--smtp-server/1.0.1
"mailer": {
"host": "email-smtp.eu-central-1.amazonaws.com",
"port": 2587,
"secure": true,
"auth": {
"user": "user",
"pass": "pass"
}
let transporter = nodemailer.createTransport(app.get('mailer'));
app.use('/mailer', mailer(transporter));
Error: connect ECONNREFUSED 127.0.0.1:587
telnet email-smtp.eu-central-1.amazonaws.com 2587
Trying 18.194.112.51...
Connected to email-smtp.eu-central-1.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-W0F3CN0 OMZCUaPbOVT1Ookc
import as fs from 'fs';
import as _ from 'lodash';
import {browser} from "protractor";
let retry = require('retry'),
googleAuth = require('google-auth-library'),
google = require('googleapis'),
gmail = google.gmail('v1');
export class GmailHelper {
// Getting an auth object
static getAuth() {
let auth = new googleAuth(),
oauth2Client = new auth.OAuth2(
myCreds.client_id,
myCreds.client_secret,
myCreds.redirect_uris[0]
),
oauth2Client.credentials = {"client_id": "159ab9cfa0b5f30e",};
return oauth2Client;
}
// Converts the query passed as an object into a string
private static convertQuery(query: any): string {
return _.map(query, (operator, item) => `${item}:${operator}`).join(' ');
}
// Retrieve a list of emails, matching the specified query, from the authenticated inbox. The query is an object like: {from: ''}
async searchForEmails(query: any): Promise<Array<any>> {
const res_1 = await this.googleCallWrapper((cb: any) => {
gmail.users.messages.list({
auth: GmailHelper.getAuth(),
userId: 'me',
q: GmailHelper.convertQuery(query)
}, cb);
}, (err: any, res: { messages: any; }) => {
return err ? err : res.messages == undefined;
});
return res_1.messages;
}
// Retrieve the full data of a specific email from the authenticated inbox
async getEmailContent(id: any): Promise<any> {
const res_1 = await this.googleCallWrapper((cb: any) => {
gmail.users.messages.get({
auth: GmailHelper.getAuth(),
userId: 'me',
id: id
}, cb);
}, (err: any, res: any) => {
return err;
});
return res_1;
}
// Wraps all types of gmail calls into promise notation and retries the call x number of times with a scaling up timeout
// Also performs `browser.waitForAngular()` before the call in order to allow the operation on the page to finish before
// checking for the email
/**
* @param googleCall {Function(googleCallback: Function) : Void} a function which performs a GoogleAPI call. When called, it is passed a GoogleAPI callback function which needs to be passed to the GoogleAPI
* @param shouldRetry {Function(error: string, response: Object) : boolean} a function which decides whether we should retry the GoogleAPI call. When called, it is passed the same arguments as the GoogleAPI callback function. It should return true if an error occurred or if the response is not satisfactory
**/
googleCallWrapper(googleCall: Function, shouldRetry: Function): Promise<any> {
return new Promise(async (resolve, reject) => {
let operation = retry.operation({
retries: 4,
minTimeout: 1000,
maxTimeout: 3000,
factor: 1.5,
});
try {
await browser.waitForAngular();
return operation.attempt(function (currentAttempt: any) {
googleCall((err: any, res: any) => {
if (operation.retry(shouldRetry(err, res))) {
console.log('Retrying the email check');
return;
}
if (err) {
console.log('Email not found!');
reject(err);
} else {
console.log('Email found!');
resolve(res);
}
});
});
} catch (err_1) {
reject(err_1);
}
})
}
}
static getAuth() {
let auth = new googleAuth(),
oauth2Client = new auth.OAuth2(
myCreds.client_id,
myCreds.client_secret,
myCreds.redirect_uris[0]
),
oauth2Client.credentials = {"client_id": "159ab9cfa0b5f30e",};
return oauth2Client;
}
const mail = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD
}
})
mail error: Connection timeout {"code":"ETIMEDOUT","command":"CONN","stack":"Error: Connection timeout\n at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:774:19)\n at SMTPConnection._onError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:760:20)\n at Timeout.<anonymous> (/app/node_modules/nodemailer/lib/smtp-connection/index.js:229:22)\n at listOnTimeout (node:internal/timers:556:17)\n at processTimers (node:internal/timers:499:7)","timestamp":"2021-02-01 19:19:49"}