chirag04 / mail-listener2

Mail listener library for node.js. Get notification when new email arrived.
MIT License
245 stars 116 forks source link

How can I only recieve the newest email instead of all of unread emails? #66

Open wnbupt opened 7 years ago

wnbupt commented 7 years ago

Everytime I use mailListener.on("mail", function(mail, seqno, attributes){} I can get all of unseen Emails, But I just want to receive the new coming emails. Looking for help, Thank you

dreams-and-thoughts commented 7 years ago

Have you tried this setting?

fetchUnreadOnStart: false, // use it only if you want to get all unread email on lib start. Default isfalse,

wnbupt commented 7 years ago

Yes. But it only helps on the beginning. When I recieve new email later,I will get all the unread mails again.Maybe the problem is that I can't mark my emails as seen.By the way,I am using QQ mail, not Gmail. THX l @comfytoday

rafaelcmrj commented 6 years ago

same here... @wnbupt did you figure this out?

rajavijayavendan commented 6 years ago

I am facing the same issue. Any possible fix?

mayeaux commented 6 years ago

Make sure to set markSeen: true when you originally fetch your emails

rajavijayavendan commented 6 years ago

Thanks anyways @mayeaux .I am already doing it. But no use

rajavijayavendan commented 6 years ago

This is my search filter searchFilter: ["UNSEEN"], markSeen: true

mayeaux commented 6 years ago

Can you post your full set of code? Will help to see everything going on

rajavijayavendan commented 6 years ago

var mailListener = new MailListener({ username: mailConfigOption.listener.user, password: mailConfigOption.listener.pass, host: mailConfigOption.host, port: 993, // imap port tls: true, connTimeout: 10000, authTimeout: 5000, debug: console.log, tlsOptions: { rejectUnauthorized: false }, mailbox: "INBOX", searchFilter: ["UNSEEN"], markSeen: true, fetchUnreadOnStart: false, mailParserOptions: { streamAttachments: false }, attachments: true, attachmentOptions: { directory: "uploads/" } });

mailListener.start(); // start listening

// stop listening // mailListener.stop();

mailListener.on("server:connected", function () { console.log("imapConnected"); });

mailListener.on("server:disconnected", function () { console.log("imapDisconnected"); });

mailListener.on("error", function (err) { console.log(err); });

mailListener.on("mail", function (mail, seqno, attributes) { MailFeedProcessor.processMailFeed(mail, seqno, attributes); });`

@mayeaux

amrsa1 commented 4 years ago

does anyone knows how to throw an error if the email wasn't received, when i set specific filter pramater that should make test fail as there are no emails, console print "wait for email" then after 60 sec print "impaDisconnected" but protractor waiting and wont terminate the test , i have tried to add test time out but didnt work gives same result

it('1-should login with a registration code sent to an email', function (done) { setTimeout(function () { flow.execute(browser.params.getLastEmail) .then(function (email) { expect(email.subject) .toEqual('thetester@abc.com submitted feedback'); expect(email.headers.to) .toEqual('aabcttidm@abc.com'); expect(email.html.includes('User feedback details: accountId: 12345, related To: dashboard, description: ' + D.feedbackMsg + '')) .toEqual(true); console.log(email.html); done(); }); }, 5000); }); });

hesyar commented 4 years ago

Any solution on this? I face the same problem

ZumelzuR commented 3 years ago

I solved like, on the protractor config, onPrepare

        var currentTime =  new Date().getTime()
        var mailListener = new MailListener({
              ...
              markSeen: true,
              port: 993, // imap port 
              tls: true,
              searchFilter: ["UNSEEN",["SINCE", currentTime + 10000]]
                ...
})

...