Skip to content

Commit f4ac98c

Browse files
authored
Add remaining sections
1 parent 6b27879 commit f4ac98c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

examples/helpers/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,35 @@ After creating a dictionary, you can go ahead and create a `Personalization` obj
3535
for to_addr in personalization['to_list']:
3636
mock_personalization.add_to(to_addr)
3737
```
38+
39+
### Creating Attachments
40+
41+
To create attachments, we use the `Attachment` class and make sure the content is base64 encoded before passing it into attachment.content.
42+
```
43+
attachment = Attachment()
44+
attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl"
45+
"Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
46+
```
47+
Another example: [Link](https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/attachment.md)
48+
49+
### Managing Settings
50+
51+
To configure settings in mail, you can use the `MailSettings` class. The class takes some [parameters](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail_settings.py#L1)(such as bcc_settings, bypass_list_management, footer_settings, sandbox_mode)
52+
53+
To add tracking settings, you can add `TrackingSettings` class. See example [here](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail_example.py#L118) and parameters and usage [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/tracking_settings.py).
54+
55+
### Sending email
56+
57+
After you have configured every component and added your own functions, you can send emails.
58+
```
59+
sg = SendGridAPIClient()
60+
data = build_kitchen_sink()
61+
response = sg.client.mail.send.post(request_body=data)
62+
```
63+
Make sure you have [environment variable](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key) set up!
64+
Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L203).
65+
66+
### Using Dynamic Templates
67+
You can use dynamic (handlebars) transactional templates to make things easy and less time taking. To make this work, you should have dynamic template created within your SendGrid account.
68+
69+
See Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L221).

0 commit comments

Comments
 (0)