Files

58 lines
2.2 KiB
Markdown

# Direct SMTP send (without Himalaya)
Use this when composing and sending a single email without installing the Himalaya CLI.
## Prerequisites
- A password file at `/root/.config/himalaya/<account>.pass` with the plaintext password
- SMTP server host and port (typically 587 for STARTTLS, 465 for SSL)
## Pattern
```python
import smtplib
from email.mime.text import MIMEText
pw = open("/root/.config/himalaya/<account>.pass").read().strip()
msg = MIMEText("Body text here.")
msg["From"] = "sender@domain.com"
msg["To"] = "recipient@example.com"
msg["Subject"] = "Subject line"
with smtplib.SMTP("mail.domain.com", 587) as s:
s.starttls()
s.login("sender@domain.com", pw)
s.send_message(msg)
```
## Notes
- Adjust host, port, account, and password file path per deployment.
- Port 587 with `starttls()` is the most common; use `SMTP_SSL(host, 465)` for direct SSL.
- The password file is typically mode `0600` — the one created by `himalaya account configure`.
- For multipart or HTML messages, use `email.mime.multipart.MIMEMultipart` and `email.mime.text.MIMEText` with `_subtype='html'`.
- For attachments, use `MIMEBase` or `email.mime.application.MIMEApplication`.
## Email-to-SMS gateway sending
Carrier SMS gateways convert an email to a text message. Keep the body short (SMS length, ~160 characters recommended for full delivery).
T-Mobile: `NUMBER@tmomail.net`
Verizon: `NUMBER@vtext.com`
AT&T: `NUMBER@txt.att.net`
Sprint: `NUMBER@messaging.sprintpcs.com`
Sending is identical to regular SMTP — set `To` to the SMS gateway address. Plain `MIMEText` with a short body works best.
### Daily recurring SMS via email
For a scheduled daily humorous/obnoxious message sent to a phone number:
1. Create a cron job prompt that generates **unique** subject and body each day. Include the recipient's name for personalization.
2. The prompt must forbid spam trigger words (free, limited time, act now, etc.) to avoid SMS gateway filtering.
3. Use `deliver='origin'` so confirmation arrives in your chat.
4. Test with a one-off SMTP send before scheduling so the user can verify delivery.
The cron job handles content generation — no static script needed for the creative part.