I have this email server that I have to create as a microservice for two web applications that the company I work on, and the architecture is somewhat like this:
- Node app running a scan every x minutes through a list of clients emails and checking if there are any new emails (these clients' emails can have numerous different domains);
- If there is a new email to that particular client, it will invoke a lambda function to connect to that particular email (with node-imap module, using imap protocol) and perform some actions with the unread email;
- I got it all working at my localhost, I can search through all the email locally and perform all the operations that I need by simulating the execution of an AWS Lambda on my machine;
- The problem is invoking the Lambda when its actually in "production" (lambda function actually in AWS Lambda), it does not seem to connect to the email address even if everything is fine (parameters for new Imap are all ok);
- I the exports.handler is being called (i checked by using some console.logs) and the parameters are all fine (i've hard coded them just to be sure);
This got me thinking that maybe the AWS Lambda functions cant connect to email providers just like my machine can, maybe I need some extra tweeking on the AWS console;
Anyone has any ideas on what is going on? I tried searching through google, but could not find anything related.
I'm using Node and node-imap package at my lambda to connect to imap server and search through the unread messages. The code for my lambda:
const Imap = require('imap');
exports.handler = async(event) => {
const payloadObj = event;
const imap = new Imap({
user: payloadObj.email,
password: payloadObj.pwd,
host: payloadObj.provider,
port: 993,
tls: true
});
imap.once('ready', function() {
console.log('Connection stablished'); // never triggered
imap.end();
});
imap.once('end', function() {
console.log('Connection ended'); // never triggered
});
imap.connect();
};
Thanks in advance to all of you who read it this far.
:)