Automatischer PDF-Druck per E-Mail und REST API
| MailPrint | ||
| MailPrintConfig | ||
| .gitignore | ||
| build.bat | ||
| MailPrint.sln | ||
| README.md | ||
MailPrint
Windows-Dienst zum automatischen Drucken von PDF-Anhängen aus E-Mails und per REST API.
Kostenlos und quelloffen.
Features
- 📧 IMAP / POP3 – Postfächer werden automatisch abgerufen, PDF-Anhänge sofort gedruckt
- 🖨️ Mehrere Drucker-Profile – je Profil eigener Drucker, Papierfach und Kopienanzahl
- 📬 Mehrere Postfächer – jedes Postfach zeigt auf ein Drucker-Profil
- 🌐 REST API – PDF per HTTP-Upload oder URL drucken (z.B. aus einem Webshop)
- 🔒 API-Key Absicherung – optionaler Schutz für den HTTP-Endpunkt
- 🗂️ Papierfach-Steuerung – SumatraPDF-basiert, stiller Druck ohne Fenster
- ✉️ Whitelist / Blacklist – global und pro Drucker-Profil
- ⚙️ Config-Tool – WinForms GUI zum Konfigurieren ohne JSON-Bearbeitung
- 🔄 Windows Service – läuft ohne Anmeldung im Hintergrund
Voraussetzungen
- Windows 10 / Server 2019 oder neuer
- .NET 10 Runtime (Windows)
- SumatraPDF (wird automatisch erkannt wenn installiert oder neben der EXE)
- Installierter Windows-Drucker
Installation
1. Release entpacken
Inhalt des publish-Ordners in ein Zielverzeichnis kopieren, z.B.:
C:\Services\MailPrint\
2. Konfigurieren
MailPrintConfig.exe starten und konfigurieren:
- Drucker-Profile – Drucker + Papierfach + optionale Absender-Filter
- Postfächer – IMAP/POP3 Zugangsdaten + zugeordnetes Drucker-Profil
- Web API – Port, API-Key, FritzBox-Portmapping
- Filter – globale Whitelist/Blacklist
- Allgemein – Intervall, SumatraPDF-Pfad, Temp-Verzeichnis
Auf Speichern klicken.
3. Als Windows Service installieren
# Als Administrator ausführen:
.\install-service.ps1
4. Deinstallieren
# Als Administrator ausführen:
.\uninstall-service.ps1
Web API
| Methode | Endpunkt | Beschreibung |
|---|---|---|
POST |
/api/print/upload |
PDF hochladen (multipart/form-data) |
POST |
/api/print/url |
PDF-URL übergeben |
GET |
/api/print/printers |
Drucker + Papierfächer auflesen |
GET |
/api/print/health |
Healthcheck |
GET |
/swagger |
Swagger UI |
Authentifizierung
X-Api-Key: <dein-api-key>
Beispiel Upload (curl)
curl -X POST http://localhost:5100/api/print/upload \
-H "X-Api-Key: DEIN_KEY" \
-F "file=@rechnung.pdf" \
-F "printer=HP LaserJet" \
-F "paperSource=Fach 2" \
-F "copies=1"
Beispiel URL (PowerShell)
Invoke-RestMethod -Uri "http://localhost:5100/api/print/url" `
-Method Post `
-Headers @{"X-Api-Key" = "DEIN_KEY"; "Content-Type" = "application/json"} `
-Body '{"url":"https://example.com/rechnung.pdf","copies":1}'
FritzBox Portmapping
FritzBox → Heimnetz → Netzwerk → Portfreigaben:
- Protokoll: TCP
- Externer Port: z.B.
5100 - Interner Host: IP des Windows-PCs
- Interner Port:
5100
In appsettings.json bzw. Config-Tool: BindAllInterfaces: true setzen.
Papierfach-Steuerung
SumatraPDF wird automatisch gefunden wenn:
- Installiert unter
C:\Program Files\SumatraPDF\ - Installiert unter
%LOCALAPPDATA%\SumatraPDF\ SumatraPDF.exeliegt nebenMailPrint.exe
Ohne SumatraPDF: Fallback auf Windows Shell-Print (kein Papierfach-Support).
Logs
- Konsole (wenn als EXE gestartet)
logs\mailprint-YYYYMMDD.log(neben der EXE)- Windows EventLog unter „MailPrint" (wenn als Service)
Lizenz
MIT