Giter Club home page Giter Club logo

smtp-tg's Introduction

SMTP-TG

SMTP to Telegram mail forwarder with file-backed persistent queue.

Libs: asyncio, aiosmtpd, email, aiogram.

Forwarding logic:

  • receives everything
  • numeric user in @tg forwarded to corresponding Telegram chat (12345678@tg to TG chat 12345678)
  • any others to DEFAULT_CHAT
  • preserve msgs order

Errors handling:

  • Any network error defers sending with a progressive delay (from TG_RETRY_PERIOD_MIN to TG_RETRY_PERIOD_MAX, doubled on each subsequent error, reset at success)
  • Other (permanent) errors sent to DEFAULT_CHAT if available, otherwise logged.

Telegram message formatting:

  • From, To
  • Subject: if present
  • Body: result of email.message.EmailMessage.get_body()
  • File with raw email attached if body not found or there is more than one part in multipart email.

Configuration with self-describing environment variables:

  • SMTP_HOST
  • SMTP_PORT
  • MAIL_QUEUE_FOLDER
  • TG_TOKEN
  • TG_DEFAULT_CHAT
  • TG_RETRY_PERIOD_MIN
  • TG_RETRY_PERIOD_MAX
  • STOP_TIMEOUT (timeout for waiting for graceful finish after SIGINT or SIGTERM signals)

Container build:

podman build -t rokiden/smtptg:latest -t rokiden/smtptg:$(date +%s) .

Container run:

podman run --name smtptg -e MAIL_QUEUE_FOLDER=/mqueue -e TG_TOKEN=<YOUR_TOKEN> -e TG_DEFAULT_CHAT=<YOUR_CHAT_ID> -v /etc/localtime:/etc/localtime:ro -v ./mqueue:/mqueue rokiden/smtptg:latest

Note:

I'm using Postfix with big queue as always-ready-to-receive endpoint, configured to forward everything (except postmaster mail) to SMTP-TG when available, otherwise defer. SMTP-TG response OK only after saving msg to file. This way I get loss-proof mail delivery, with ability to restart/maintenance SMTP-TG container or whole Podman/Docket.

Postfix config:

... defaults ...
inet_interfaces = 10.89.0.1, 127.0.0.1
inet_protocols = ipv4
mynetworks = 10.89.0.0/24, 127.0.0.0/8
# 10.89.0.0/24 podman network
myhostname = <MYHOSTNAME>
mydomain = lan
myorigin = $myhostname
mydestination = forcelocal
# mail sent to @forcelocal doesnt forward
relayhost = [smtptg.dns.podman]:2525
maximal_backoff_time = 10m
minimal_backoff_time = 1m
queue_run_delay = 1m
maximal_queue_lifetime = 30d
bounce_queue_lifetime = 0
smtpd_peername_lookup = no
notify_classes=resource, software, 2bounce
postmaster = <MYUSER>@forcelocal
2bounce_notice_recipient = $postmaster
bounce_notice_recipient = $postmaster
delay_notice_recipient = $postmaster
error_notice_recipient = $postmaster

smtp-tg's People

Contributors

rokiden avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.