jasp402 / Easy-YOPmail

📮 YOPmail emails manager from an NPM NodeJS library
https://jasp402.github.io/Easy-YOPmail/starter-topic.html
19 stars 3 forks source link

Having issues reading the subject #16

Closed SomeTroller77 closed 6 months ago

SomeTroller77 commented 6 months ago

hey, i was trying to read messages from my mail, but everything is empty,

{ id: 'e_ZwDjAGVkZGVlAwHmZQNjAGR4ZwH1Zj==', submit: '', from: '', date: '', selector: '#mail', format: 'TXT', data: '' }

{ settings: {}, search: {}, totalInbox: 1, totalPages: 1, mailFromPage: { page_1: 1 }, totalGetMails: 1, inbox: [ { id: 'e_ZwDjAGVkZGVlAwHmZQNjAGR4ZwH1Zj==', from: 'Instagram', subject: '** is your Instagram code', timestamp: '18:26' } ] }

jasp402 commented 6 months ago

Hi. To read a YOPmail message, there are 2 parts.

1.- Obtain the email ID using getInbox() in this way

const easyYopmail = require('easy-yopmail');
easyYopmail.getInbox('testEmail@yopmail.com').then(email=>{
console.log(email.inbox);
//we obtain an object with the property "Inbox" which is an array of objects
//that contain the emails found.
    {
    id: 'e_ZwDjZmZkZwV0ZGN1ZQNjAGN1ZGLlBN==',
        from: 'Disqus',
        subject: 'Re: Comment on Rehab Afterlife',
        timestamp: '17:41',
        page: 5
    }
}); 

2.- Read the message with the ID using readMessage() like this

//once we get the ID we can query it directly using readMessage()
easyYopmail.readMessage('testEmail@yopmail.com', 'e_ZwDjZmZkZwV0ZGN1ZQNjAGN1ZGLlBN==').then(message =>{
console.log(message);
});
//we will obtain a result similar to this:
{
    id: 'e_ZwDjZmZkZwV0ZGN1ZQNjAGN1ZGLlBN==',
    submit: 'Re: Comment on Rehab Afterlife',
    from: 'Disqus @maas.disqus.com>',
    date: 'Sunday, March 31, 2024 5:41:05 PM',
    deliverability: 'Your account has been credited',
    format: 'txt',
    selector: null,
    eq: null,
    attribute: null,
    pathToSave: null,
    content: "You have a new reply from 𝓡𝓸𝓼𝓪 in Disqus Rehab View Reply New Channels are live: Anime, Pets, and Literature! Check them out Disqus, 1 California St., Suite 1225, San Francisco, CA 94111 You're receiving this messa
    ge because you've signed up for Disqus notifications. Unsubscribe Change Email Notifications id-2889cd94c1154f27b3b05244a67d7005",
    info: []
}

I hope this helped you, you must provide additional information, I do not see the email you are trying to consult, nor the implemented functions. Nor how you are implementing it. If the problem persists, please provide us with as much data as possible so we can replicate what you are trying to do.

SomeTroller77 commented 6 months ago

readMessage(): Error read message Cannot read properties of undefined (reading 'toLowerCase') D:\Coding\JS\Projects\InstaBotnet\node_modules\easy-yopmail\index.js:1 "use strict";const cheerio=require("cheerio"),querystring=require("querystring"),constants=require("./src/constants.js"),utils=require("./src/utils.js");class EasyYopmail{async getMail(){try{const a=await utils.request("GET",constants.GENERATOR_URL);if(200!==a.statusCode)return console.error(constants.ERROR_LOAD_PAGE),null;const b=cheerio.load(a.body),c=b(constants.S_INPUT_MAIL_GENERATE).text();return c.split(";")[1]||c}catch(a){throw console.error(constants.ERROR_LOAD_PAGE),console.error(a.message),new Error(a)}}async getInbox(a){let b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{};try{const d=utils.simplifyEmail(a),{cookie:e,yp:f,ver:g}=await utils.getCookiesAndYP(),h=await utils.getYJ(e,g);return await utils.detailInbox(d,f,h,g,e,b,c)}catch(a){throw console.error(constants.ERROR_GET_INBOX),console.error(a.message),new Error(a)}}async readMessage(a,b,c){let d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:"";try{const{cookie:e}=await utils.getCookiesAndYP(),f=await utils.request("GET",constants.READ_MAIL_URL(a,b),constants.INBOX_HTTP_CONFIG(e,a));200!==f.statusCode&&console.log(constants.ERROR_LOAD_PAGE);const g=cheerio.load(f.body),h=g(constants.SELECTOR_SUBMIT).text(),i=g(constants.SELECTOR_FROM),j=g(constants.SELECTOR_DATE),k=i.length?i.text():g(constants.SELECTOR_FROM_ALT).text(),l=j.length?j.text().replace(k,""):g(constants.SELECTOR_DATE_ALT).text();let m;return d?(d="".concat(constants.SELECTOR_MAIL," ").concat(d),m="html"===c.toLowerCase()?g(d).html():g(d).text().trim()):(d="#mail",m="html"===c.toLowerCase()?g(d).html():g(d).text().trim()),{id:b,submit:h,from:k,date:l,selector:d,format:c,data:m}}catch(a){throw console.error(constants.ERROR_READ_MESSAGE),console.error(a.message),new Error(a)}}async deleteMessage(a,b){try{const{cookie:c,yp:d,ver:e}=await utils.getCookiesAndYP(),f=await utils.getYJ(c,e),{inbox:g}=await this.getInbox(a,{id:b});if(0<g.length){const g=constants.DELETE_MESSAGE_URL(a,b,d,f,e),h=await utils.request("GET",g,constants.INBOX_HTTP_CONFIG(c,a));return!(200!==h.statusCode)}return!1}catch(a){throw console.error(constants.ERROR_DELETE_MESSAGE),console.error(a.message),new Error(a)}}async writeMessage(a,b,c,d){try{a&&b&&c&&d||console.error(constants.ERROR_MISSING_PARAMETERS);const{cookie:e}=await utils.getCookiesAndYP(),f=await utils.request("GET",constants.WRITE_MAIL_URL(a),constants.INBOX_HTTP_CONFIG(e,a));if(200===f.statusCode){const f={msgfrom:"".concat(a,"@yopmail.com"),msgto:b,msgsubject:c,msgbody:d},g=querystring.stringify(f);let h=constants.WRITE_MESSAGE_HTTP_CONFIG(e,a);h.headers["Content-Type"]="application/x-www-form-urlencoded",h.headers["Content-Length"]=Buffer.byteLength(g);const i=await utils.request("POST",constants.SEND_MESSAGE_URL,h,g);return 200!==i.statusCode&&console.error(constants.ERROR_WRITE_MESSAGE),(i.body+"").split("|")[2]}return f.data}catch(a){throw console.error(constants.ERROR_WRITE_MESSAGE),console.error(a.message),new Error(a)}}async deleteInbox(a){try{const{cookie:b,yp:c,ver:d}=await utils.getCookiesAndYP(),e=await utils.getYJ(b,d),{inbox:f}=await this.getInbox(a);if(0<f.length){const g=f[0].id,h=constants.DELETE_INBOX_URL(a,g,c,e,d),i=await utils.request("GET",h,constants.INBOX_HTTP_CONFIG(b,a));return console.log(i),200===i.statusCode}return!1}catch(a){throw console.error(constants.ERROR_DELETE_INBOX),console.error(a.message),new Error(a)}}}module.exports=new EasyYopmail;

Error: TypeError: Cannot read properties of undefined (reading 'toLowerCase') at EasyYopmail.readMessage (D:\Coding\JS\Projects\InstaBotnet\node_modules\easy-yopmail\index.js:1:1796) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///D:/Coding/JS/Projects/InstaBotnet/index.js:50:31

Node.js v20.5.0

facing this issue when i use your snippet, i have put my own mail and id in place where its needed