mail-proton-api
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

mail-proton-api

Unofficial API for ProtonMail. Works both in browser and Node.js

Usage example

const protonmail = require('mail-proton-api');

(async () => {
    const client = new protonmail.ProtonmailClient();

    // login to the protonmail
    await client.login({
        username: process.env.PROTONMAIL_USERNAME,
        loginPassword: process.env.PROTONMAIL_PASSWORD,
    });

    // fetch private keys in order to decrypt messages
    await client.fetchKeys({
        password: process.env.PROTONMAIL_PASSWORD,
    });

    // fetch the first 10 messages
    const messagesResponse = await client.messages.list({
        LabelID: protonmail.DefaultLabels.All,
        Limit: 10,
        Page: 0,
    });
    
    // take the first one
    const firstMessage = messagesResponse.Messages[0];
    // get the full message with body
    const m = await client.messages.get(firstMessage.ID);

    // decrypt message
    const m_decrypted = await client.decryptMessage(m.Message);

    // here is your message body. you can do anything with it
    console.log(m_decrypted);

    // move the message to trash
    await client.messages.label([firstMessage.ID], protonmail.DefaultLabels.Trash);
    // delete the message
    await client.messages.delete([firstMessage.ID]);
})();

Readme

Keywords

Package Sidebar

Install

npm i mail-proton-api

Weekly Downloads

288

Version

1.1.0

License

MIT

Unpacked Size

2.75 MB

Total Files

45

Last publish

Collaborators

  • qwinkler