mailosaur / mailosaur-node

Mailosaur email and SMS testing library for Node.js

Home Page:https://mailosaur.com/docs/languages/nodejs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error encounter

WahyuAgungBudiyanto opened this issue · comments

Hi sir i encounter error like this when i trying to run my script to fetch any email messages

F:\desktop\aap\node_modules\mailosaur\lib\mailosaur.js:47
return new MailosaurError('Not found, check input parameters.', 'invalid_request', httpStatusCode, httpResponseBody);
^

MailosaurError: Not found, check input parameters.
at MailosaurClient.httpError (F:\desktop\aap\node_modules\mailosaur\lib\mailosaur.js:47:16)
at F:\desktop\aap\node_modules\mailosaur\lib\operations\messages.js:61:44
at IncomingMessage. (F:\desktop\aap\node_modules\mailosaur\lib\request.js:94:9)
at IncomingMessage.emit (node:events:524:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errorType: 'invalid_request',
httpStatusCode: 404,
httpResponseBody: '{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.4","title":"Not Found","status":404,"traceId":"00-bc5e3251e4b99aa6a323e10dc820f855-dbe4c54cdb87a539-00"}'
}

Node.js v19.5.0`

is it because the interal is too fast to read the messages? My script is just search for any mesages that has certain header and open the link verification inside

Can I just ignore or delete the duplicated to.email? so it will not got error. cause many people trying to spam verification code and it will result of duplicated messages

commented

Hi there, can you share the code you're running. This error will happen if you're not using the correct syntax with your code.

(async` () => {
const MailosaurClient = require('mailosaur');
const https = require('https');
const { JSDOM } = require('jsdom');
const axios = require('axios');

const mailosaur = new MailosaurClient('');
const serverDomain = '';
const webhookURL =
'';
const words = serverDomain.split('.');
const serverId = words[0];

const searchCriteria = {
sentTo: '@' + serverDomain,
subject: "New Account Verification"
};

const processedWords = [];

axios.post(webhookURL, { content: Logged in as ${serverDomain}});
console.log('Logged in as', serverDomain);

let hasCalledDeleteAllEmails = false;
const deleteAllEmails = async () => {
if (!hasCalledDeleteAllEmails) {
hasCalledDeleteAllEmails = true;
await mailosaur.messages.deleteAll(serverId);
axios.post(webhookURL, { content: 'All messages has been deleted every 1 hour' });
}
};

setInterval(() => {
hasCalledDeleteAllEmails = false;
}, 3600000);

setInterval(deleteAllEmails, 3600000);

while (true) {
try {
const limits = await mailosaur.usage.limits();
const message = await mailosaur.messages.get(serverId, searchCriteria, { receivedAfter: new Date(2023, 01, 01) });
const firstLink = message.html.links[0];

  https.get(firstLink.href, (res) => {
    if (res.statusCode === 302) {
      const dom = new JSDOM(message.html.body);
      const el = dom.window.document.querySelector('title');
      const verificationCode = el.textContent;
      const words = verificationCode.split(' ');
      const lastWord = words[words.length - 1];
      
   
    //console.log(lastWord, "| Success");
	
   // only send the message if it hasn't been sent before
      if (!processedWords.includes(lastWord)) {
        processedWords.push(lastWord);
	
      axios.post(webhookURL, { content: `${lastWord} | Success | Today's Usage: ${limits.email.current}/2000`});
      }

 mailosaur.messages.del(message.id);
     
    } else if (res.statusCode === 404) {
      console.log('404');
	axios.post(webhookURL, { content: "AUTO AAP stopped! DM owner" });
    }
  }).on('error', (e) => {
    console.error(e);
  });
} catch (err) {
  if (err.errorType === 'search_timeout') {
    continue;
  }
  console.error(err);
  axios.post(webhookURL, { content: "AUTO AAP stopped! DM owner" });
  break;
} 
await new Promise(resolve => setTimeout(resolve, 3000));

}
})();

sometimes the error is like socket hang up
image

I want to read unmark but its not possible, so i use delete messages method, but im still confuse about getting spam messages counter. like same header name

I mean its working properly but sometimes got error differentlu

commented

The error message in your screenshots relates to some webhook calls you're making that are unrelated to Mailosaur. If you believe you have an issue with the Mailosaur API calls themselves please reach out to the support team via our website/help link within the Mailosaur Dashboard.

image
I ask chatgpt and they answer this.