Reputation: 31
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:
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.
:)
Upvotes: 2
Views: 945
Reputation: 41
I had the same problem and I realized that the problem was with the async word
exports.handler = async(event) => {
Just remove it
exports.handler = (event) => {
or in this way
exports.handler = function(event) {
for me works perfectly.
Upvotes: 2