|
| 1 | +# Send a Single Email to a Single Recipient |
| 2 | + |
| 3 | +The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes. |
| 4 | + |
| 5 | +```python |
| 6 | +import os |
| 7 | +import sendgrid |
| 8 | +from sendgrid.helpers.mail import * |
| 9 | + |
| 10 | +client = sendgrid.SendGridClientFactory(os.environ.get('SENDGRID_API_KEY')) |
| 11 | +from_email = Email("test@example.com", "Example User") |
| 12 | +to_email = Email("test@example.com", "Example User") |
| 13 | +subject = "Sending with SendGrid is Fun" |
| 14 | +plain_text_content = "and easy to do anywhere, even with Python" |
| 15 | +html_content = "<strong>and easy to do anywhere, even with Ruby</strong>" |
| 16 | +msg = Mail.create_single_email(from_email, subject, to_email, content) |
| 17 | +try: |
| 18 | + response = client.send_email(msg) |
| 19 | +except urllib.error.HTTPError as e: |
| 20 | + print(e.read()) |
| 21 | +print(response.status_code) |
| 22 | +print(response.body) |
| 23 | +print(response.headers) |
| 24 | +``` |
| 25 | + |
| 26 | +# Send a Single Email to Multiple Recipients |
| 27 | + |
| 28 | +The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes. |
| 29 | + |
| 30 | +Coming soon |
| 31 | + |
| 32 | +# Send Multiple Emails to Multiple Recipients |
| 33 | + |
| 34 | +The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes. |
| 35 | + |
| 36 | +Coming soon |
| 37 | + |
| 38 | +# Attachments |
| 39 | + |
| 40 | +The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes. |
| 41 | + |
| 42 | +Coming soon |
| 43 | + |
| 44 | +# Transactional Templates |
| 45 | + |
| 46 | +The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes. |
| 47 | + |
| 48 | +Coming soon |
0 commit comments