jasp402 / Easy-YOPmail

đź“® YOPmail emails manager from an NPM NodeJS library
https://jasp402.github.io/Easy-YOPmail/starter-topic.html
18 stars 3 forks source link

Trying to Use The readMessage Function But it doesn't work fine #8

Closed Simokieur closed 1 year ago

Simokieur commented 1 year ago

readMessage(): Error read message Request failed with status code 400 Error reading message: Error: AxiosError: Request failed with status code 400 at Object.readMessage (C:\Users\xx\node_modules\easy-yopmail\dist\index.js:1:2504) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {stack: 'Error: AxiosError: Request failed with status…ions (node:internal/process/task_queues:95:5)', message: 'AxiosError: Request failed with status code 400'}

https://runkit.com/embed/jx1qgfuqcepk

jasp402 commented 1 year ago

I have examined your code and developed a simplified version of the desired functionality, which appears functional on my end. Nonetheless, I encountered a 400 error when running your code, and was unable to determine the root cause of the issue. I trust that the simplified version of the code could be of assistance to you. I have also observed that the "txt" or "html" format is mandatory. You may consider setting it as the default value to be more user-friendly. This is subject to future changes.

var easyYOPmail = require("easy-yopmail")

const desiredSubject = "Votre code de sécurité Ankama";
const email= 'gxajmdcwcpjl'; // Replace this with the actual E-MAIL

easyYOPmail.getInbox(email, {subject:desiredSubject}).then(({inbox,id}) => {
    easyYOPmail.readMessage(email, 'e_ZwZjAmV3ZQVmZGZ0ZQNjZQp1BGx1BN==','txt').then(message => {
        const securityCodeRegex = /[A-Z0-9]{6}/; // Assuming the code is always 6 characters of uppercase letters and numbers
        const securityCodeMatches = message.data.match(securityCodeRegex);
        if (securityCodeMatches && securityCodeMatches.length > 0) {
            const securityCode = securityCodeMatches[0];
            console.log('Extracted security code:', securityCode);
        } else {
            console.log('Security code not found in the email message.');
        }
    });
});
Simokieur commented 1 year ago

Hello bro, thanks for your support. I believe I've identified the issue. It occurred because I used capitalized letters in the email address.