34 lines
1.4 KiB
Markdown
34 lines
1.4 KiB
Markdown
# Daily Tech Digest — HTML Email with Clickable Links
|
|
|
|
The digest script at `/root/.hermes/scripts/daily-feed-summary.py` historically sent as **plain text** — markdown links `[title](url)` were not clickable.
|
|
|
|
## Fix: multipart MIME with HTML conversion
|
|
|
|
Convert the markdown body to HTML before sending:
|
|
|
|
```python
|
|
import re
|
|
html_body = re.sub(r'\[([^\]]+)\]\(([^)]+)\)',
|
|
r'<a href="\2" style="color:#2563eb;">\1</a>', body)
|
|
html_body = re.sub(r'\*\*([^*]+)\*\*', r'<strong>\1</strong>', html_body)
|
|
html_body = re.sub(r'_([^_]+)_', r'<em>\1</em>', html_body)
|
|
html_body = re.sub(r'^## (.+)$', r'<h2>\1</h2>', html_body, flags=re.MULTILINE)
|
|
html_body = re.sub(r'^# (.+)$', r'<h1>\1</h1>', html_body, flags=re.MULTILINE)
|
|
html_body = re.sub(r'^---+$', r'<hr>', html_body, flags=re.MULTILINE)
|
|
```
|
|
|
|
Send as `MIMEMultipart('alternative')` — attach both the original plain text AND the converted HTML. Email clients render the HTML version if supported, fall back to plain text otherwise.
|
|
|
|
```python
|
|
from email.mime.text import MIMEText
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
msg = MIMEMultipart('alternative')
|
|
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
|
msg.attach(MIMEText(html, 'html', 'utf-8'))
|
|
```
|
|
|
|
## Permanence
|
|
|
|
This only applies to scripts that generate markdown-rich content for email. Simple notification emails (cron alerts, bounce checks, inbox summaries) don't need HTML — plain text is fine and faster.
|