You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mailtrap provides a dedicated API to manage reusable email templates. The
128
+
client exposes several helper methods which all expect your account identifier
129
+
as the first argument:
130
+
131
+
-`email_templates(account_id)` – list all templates
132
+
-`create_email_template(account_id, data)` – create a new template
133
+
-`update_email_template(account_id, template_id, data)` – update a template
134
+
-`delete_email_template(account_id, template_id)` – remove a template
135
+
136
+
#### Creating a template
137
+
138
+
The `data` dictionary **must** contain `name`, `subject` and `category`. You can
139
+
optionally provide `body_html` and/or `body_text` to store the template content.
140
+
141
+
```python
142
+
import mailtrap as mt
143
+
144
+
client = mt.MailtrapClient(token="your-api-key")
145
+
146
+
# list templates
147
+
templates = client.email_templates(1)
148
+
149
+
template_data = {
150
+
"name": "Welcome",
151
+
"subject": "Welcome on board",
152
+
"category": "Promotion",
153
+
"body_html": "<h1>Hello {{user_name}}</h1>",
154
+
"body_text": "Hello {{user_name}}",
155
+
}
156
+
157
+
created = client.create_email_template(1, template_data)
158
+
159
+
# update template
160
+
client.update_email_template(1, created["id"], {"subject": "New subject"})
161
+
162
+
# delete template
163
+
client.delete_email_template(1, created["id"])
164
+
```
165
+
125
166
## Contributing
126
167
127
168
Bug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-python). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
0 commit comments