yopmail-helper
Version:
yopmail helper. It will help you receive the mail content.
31 lines (26 loc) • 815 B
JavaScript
const {getInbox} = require('../inbox/inbox');
const {getMailDetailsHtml} = require('./mail-details');
const {parse} = require('node-html-parser');
async function getLinkOfFirstMail(mailAddress) {
mailAddress = (mailAddress.split('@')[0] || '').toLowerCase() || mailAddress;
const result = [];
const mails = await getInbox(mailAddress);
if (!mails || mails.length === 0) {
return result;
}
const idOfFirstMail = mails[0].id;
const mailDetail = await getMailDetailsHtml(idOfFirstMail, mailAddress);
const selectorAll = parse(mailDetail).querySelectorAll('a');
selectorAll.forEach(
(item) => {
const href = item.getAttribute('href');
if (href != null) {
result.push(href);
}
},
);
return result;
}
module.exports = {
getLinkOfFirstMail,
};