---
# System prepended metadata

title: Git Patch Email - Titan

---

# Git Patch Email - Titan

See linux kernel [patching](https://hackmd.io/uqf9iuxtQ9GRahqab79tRA?view) series.

Assumes patch `sample.patch` is in the current working directory. Update as required.

Sample python code:

```python=
import smtplib
import ssl
import os
from email.mime.text import MIMEText

# Read the patch
lines = ""
with open("sample.patch", "r+") as filelines:
    lines = filelines.readlines()
# Titan SMTP server information
smtp_server = "smtp.titan.email"
smtp_port = 465
# Read credentials from environment variable
# Of course credential vaults are more secure
name = os.environ["TITAN_NAME"]
cred = os.environ["TITAN_PASS"]
# Get this from scripts/get_maintainers.pl
recipients = ["maintainer@kernel.org", "mailing-list@kernel.org"]
# SSL
context = ssl.create_default_context()
s = smtplib.SMTP_SSL(smtp_server, smtp_port, context)
s.set_debuglevel(1)
s.ehlo()
s.login(name, cred)
# Inject information from the patch
sender = lines[1].split("From: ")[1]
msg = MIMEText(''.join(lines[4:]))
msg['From'] = sender
msg['To'] = ", ".join(recipients)
msg['Subject'] = lines[3].split("Subject: ")[1]
s.sendmail(sender, recipients, msg.as_string())
s.close()

```

To make this more generic:

* Try out making `smtp_server` and `smtp_port` environment variables.
* change `TITAN_NAME` and `TITAN_PASS` to `EMAIL_NAME` and `EMAIL_PASS`, respectively.

## References

[titan](https://support.titan.email/hc/en-us/articles/4405162224665-Configuring-Titan-on-Email-Scripts)
[kernel docs](https://docs.kernel.org/index.html)