Skip to content

victoriovm/temp-mail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✉ Temp Mail

A self-hosted disposable email api that uses Cloudflare Worker.

Cloudflare Worker Config

This is the Cloudflare Worker configuration to forward emails (with Catch-All) from your domain to the API:

import PostalMime from 'postal-mime';

export default {
  async email(message, env, ctx) {
    const API_URL = "https://YOUR_API/api/receive";
    const AUTH_TOKEN = "YOUR_TOKEN";

    const to = message.to;
    const from = message.from;
    const subject = message.headers.get("subject") || "Sem assunto";
    const emailParsed = await PostalMime.parse(message.raw);

    const payload = {
      email: to,
      message: {
        from,
        subject,
        text: btoa(unescape(encodeURIComponent(emailParsed.html)))
      }
    };

    await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${AUTH_TOKEN}`
      },
      body: JSON.stringify(payload)
    });
  }
};

API Routes

Receive Email

POST /api/receive

Requires authentication - Header: Authorization: Bearer YOUR_SECRET_TOKEN

List Mails

POST /api/list

{
  "email": "user_mail"
}

Read Mail

POST /api/read

{
  "email": "user_mail",
  "id": "message_id"
}

About

A temporary email api in NodeJS with Cloudflare Worker.

Topics

Resources

Stars

Watchers

Forks