mail-listener2 icon indicating copy to clipboard operation
mail-listener2 copied to clipboard

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

Open wnbupt opened this issue 7 years ago • 12 comments

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

wnbupt avatar May 18 '17 03:05 wnbupt

Have you tried this setting?

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

dreams-and-thoughts avatar May 23 '17 00:05 dreams-and-thoughts

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

wnbupt avatar Jun 02 '17 03:06 wnbupt

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

rafaelcmrj avatar Nov 02 '17 20:11 rafaelcmrj

I am facing the same issue. Any possible fix?

rajavijayavendan avatar May 22 '18 10:05 rajavijayavendan

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

mayeaux avatar May 22 '18 17:05 mayeaux

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

rajavijayavendan avatar May 25 '18 09:05 rajavijayavendan

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

rajavijayavendan avatar May 25 '18 09:05 rajavijayavendan

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

mayeaux avatar May 25 '18 17:05 mayeaux

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

rajavijayavendan avatar May 25 '18 17:05 rajavijayavendan

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('[email protected] submitted feedback'); expect(email.headers.to) .toEqual('[email protected]'); expect(email.html.includes('User feedback details: accountId: 12345, related To: dashboard, description: ' + D.feedbackMsg + '')) .toEqual(true); console.log(email.html); done(); }); }, 5000); }); });

amrsa1 avatar Oct 23 '19 11:10 amrsa1

Any solution on this? I face the same problem

hesyar avatar Jun 22 '20 13:06 hesyar

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]]
                ...
})

...

ZumelzuR avatar Jul 21 '21 16:07 ZumelzuR