+
+2. __[Fork](https://help.github.com/fork-a-repo/)__ the [sendgrid-python](https://github.com/sendgrid/sendgrid-python) repository:
+
+
+
+3. __Clone__ your fork via the following commands:
+
+```bash
+# Clone your fork of the repo into the current directory
+git clone https://github.com/your_username/sendgrid-python
+# Navigate to the newly cloned directory
+cd sendgrid-python
+# Assign the original repo to a remote called "upstream"
+git remote add upstream https://github.com/sendgrid/sendgrid-python
+```
+
+> Don't forget to replace *your_username* in the URL by your real GitHub username.
+
+4. __Create a new topic branch__ (off the main project development branch) to contain your feature, change, or fix:
+
+```bash
+git checkout -b ThanksThe SendGrid Team
", - "text": "Thanks,/n The SendGrid Team" + "html": "ThanksThe Twilio SendGrid Team
", + "text": "Thanks,/n The Twilio SendGrid Team" }, "sandbox_mode": { "enable": False @@ -2246,9 +2247,9 @@ data = { } } response = sg.client.mail.send.post(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` # MAIL SETTINGS @@ -2257,7 +2258,7 @@ print response.headers **This endpoint allows you to retrieve a list of all mail settings.** -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings @@ -2265,9 +2266,9 @@ Mail settings allow you to tell SendGrid specific things to do to every email th ```python params = {'limit': 1, 'offset': 1} response = sg.client.mail_settings.get(query_params=params) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update address whitelist mail settings @@ -2275,7 +2276,7 @@ print response.headers The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/address_whitelist @@ -2289,9 +2290,9 @@ data = { ] } response = sg.client.mail_settings.address_whitelist.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve address whitelist mail settings @@ -2299,24 +2300,24 @@ print response.headers The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/address_whitelist ```python response = sg.client.mail_settings.address_whitelist.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update BCC mail settings **This endpoint allows you to update your current BCC mail settings.** -When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. +When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/bcc @@ -2327,34 +2328,34 @@ data = { "enabled": False } response = sg.client.mail_settings.bcc.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve all BCC mail settings **This endpoint allows you to retrieve your current BCC mail settings.** -When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. +When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/bcc ```python response = sg.client.mail_settings.bcc.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update bounce purge mail settings **This endpoint allows you to update your current bounce purge settings.** -This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. +This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/bounce_purge @@ -2366,26 +2367,26 @@ data = { "soft_bounces": 5 } response = sg.client.mail_settings.bounce_purge.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve bounce purge mail settings **This endpoint allows you to retrieve your current bounce purge settings.** -This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. +This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/bounce_purge ```python response = sg.client.mail_settings.bounce_purge.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update footer mail settings @@ -2393,7 +2394,7 @@ print response.headers The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/footer @@ -2405,9 +2406,9 @@ data = { "plain_content": "..." } response = sg.client.mail_settings.footer.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve footer mail settings @@ -2415,16 +2416,16 @@ print response.headers The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/footer ```python response = sg.client.mail_settings.footer.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update forward bounce mail settings @@ -2432,7 +2433,7 @@ print response.headers Activating this setting allows you to specify an email address to which bounce reports are forwarded. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/forward_bounce @@ -2443,9 +2444,9 @@ data = { "enabled": True } response = sg.client.mail_settings.forward_bounce.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve forward bounce mail settings @@ -2453,16 +2454,16 @@ print response.headers Activating this setting allows you to specify an email address to which bounce reports are forwarded. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/forward_bounce ```python response = sg.client.mail_settings.forward_bounce.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update forward spam mail settings @@ -2470,7 +2471,7 @@ print response.headers Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/forward_spam @@ -2481,9 +2482,9 @@ data = { "enabled": False } response = sg.client.mail_settings.forward_spam.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve forward spam mail settings @@ -2491,16 +2492,16 @@ print response.headers Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/forward_spam ```python response = sg.client.mail_settings.forward_spam.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update plain content mail settings @@ -2508,7 +2509,7 @@ print response.headers The plain content setting will automatically convert any plain text emails that you send to HTML before sending. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/plain_content @@ -2518,9 +2519,9 @@ data = { "enabled": False } response = sg.client.mail_settings.plain_content.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve plain content mail settings @@ -2528,16 +2529,16 @@ print response.headers The plain content setting will automatically convert any plain text emails that you send to HTML before sending. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/plain_content ```python response = sg.client.mail_settings.plain_content.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update spam check mail settings @@ -2545,7 +2546,7 @@ print response.headers The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/spam_check @@ -2557,9 +2558,9 @@ data = { "url": "url" } response = sg.client.mail_settings.spam_check.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve spam check mail settings @@ -2567,16 +2568,16 @@ print response.headers The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/spam_check ```python response = sg.client.mail_settings.spam_check.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update template mail settings @@ -2586,7 +2587,7 @@ This setting refers to our original email templates. We currently support more f The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### PATCH /mail_settings/template @@ -2597,9 +2598,9 @@ data = { "html_content": "<% body %>" } response = sg.client.mail_settings.template.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Retrieve legacy template mail settings @@ -2609,16 +2610,16 @@ This setting refers to our original email templates. We currently support more f The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages. -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). ### GET /mail_settings/template ```python response = sg.client.mail_settings.template.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` # MAILBOX PROVIDERS @@ -2637,9 +2638,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act ```python params = {'end_date': '2016-04-01', 'mailbox_providers': 'test_string', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'} response = sg.client.mailbox_providers.stats.get(query_params=params) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` # PARTNER SETTINGS @@ -2648,7 +2649,7 @@ print response.headers **This endpoint allows you to retrieve a list of all partner settings that you can enable.** -Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). ### GET /partner_settings @@ -2656,17 +2657,17 @@ Our partner settings allow you to integrate your SendGrid account with our partn ```python params = {'limit': 1, 'offset': 1} response = sg.client.partner_settings.get(query_params=params) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Updates New Relic partner settings. **This endpoint allows you to update or change your New Relic partner settings.** -Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). -By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). +By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). ### PATCH /partner_settings/new_relic @@ -2678,26 +2679,26 @@ data = { "license_key": "" } response = sg.client.partner_settings.new_relic.patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Returns all New Relic partner settings. **This endpoint allows you to retrieve your current New Relic partner settings.** -Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). -By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). +By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). ### GET /partner_settings/new_relic ```python response = sg.client.partner_settings.new_relic.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` # SCOPES @@ -2706,16 +2707,16 @@ print response.headers **This endpoint returns a list of all scopes that this user has access to.** -API Keys can be used to authenticate the use of [SendGrids v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissions, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html). +API Keys can be used to authenticate the use of [Twilio SendGrid's v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissions, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html). ### GET /scopes ```python response = sg.client.scopes.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` # SENDERS @@ -2726,7 +2727,7 @@ print response.headers *You may create up to 100 unique sender identities.* -Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### POST /senders @@ -2750,30 +2751,30 @@ data = { "zip": "80202" } response = sg.client.senders.post(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Get all Sender Identities **This endpoint allows you to retrieve a list of all sender identities that have been created for your account.** -Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`. ### GET /senders ```python response = sg.client.senders.get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Update a Sender Identity **This endpoint allows you to update a sender identity.** -Updates to `from.email` require re-verification. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Updates to `from.email` require re-verification. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`. Partial updates are allowed, but fields that are marked as "required" in the POST (create) endpoint must not be nil if that field is included in the PATCH request. @@ -2800,15 +2801,15 @@ data = { } sender_id = "test_url_param" response = sg.client.senders._(sender_id).patch(request_body=data) -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## View a Sender Identity **This endpoint allows you to retrieve a specific sender identity.** -Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`. ### GET /senders/{sender_id} @@ -2816,15 +2817,15 @@ Sender Identities are required to be verified before use. If your domain has bee ```python sender_id = "test_url_param" response = sg.client.senders._(sender_id).get() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Delete a Sender Identity **This endpoint allows you to delete one of your sender identities.** -Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`. ### DELETE /senders/{sender_id} @@ -2832,15 +2833,15 @@ Sender Identities are required to be verified before use. If your domain has bee ```python sender_id = "test_url_param" response = sg.client.senders._(sender_id).delete() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` ## Resend Sender Identity Verification **This endpoint allows you to resend a sender identity verification email.** -Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. +Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`. ### POST /senders/{sender_id}/resend_verification @@ -2848,2189 +2849,2193 @@ Sender Identities are required to be verified before use. If your domain has bee ```python sender_id = "test_url_param" response = sg.client.senders._(sender_id).resend_verification.post() -print response.status_code -print response.body -print response.headers +print(response.status_code) +print(response.body) +print(response.headers) ``` - -# STATS - -## Retrieve global email statistics - -**This endpoint allows you to retrieve all of your global email statistics between a given date range.** - -Parent accounts will see aggregated stats for their account and all subuser accounts. Subuser accounts will only see their own stats. - -### GET /stats + +# SENDER AUTHENTICATION -```python -params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1} -response = sg.client.stats.get(query_params=params) -print response.status_code -print response.body -print response.headers -``` - -# SUBUSERS +## Create an authenticated domain. -## Create Subuser +**This endpoint allows you to create a domain authentication for one of your domains.** -This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API. +If you are creating a domain authentication that you would like a subuser to use, you have two options: +1. Use the "username" parameter. This allows you to create a domain authentication on behalf of your subuser. This means the subuser is able to see and modify the created authentication. +2. Use the Association workflow (see Associate Domain section). This allows you to assign a domain authentication created by the parent to a subuser. This means the subuser will default to the assigned domain authentication, but will not be able to see or modify that authentication. However, if the subuser creates their own domain authentication it will overwrite the assigned domain authentication. -For more information about Subusers: +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html) -* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html) +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### POST /subusers +### POST /whitelabel/domains ```python data = { - "email": "John@example.com", + "automatic_security": False, + "custom_spf": True, + "default": True, + "domain": "example.com", "ips": [ - "1.1.1.1", - "2.2.2.2" + "192.168.1.1", + "192.168.1.2" ], - "password": "johns_password", - "username": "John@example.com" + "subdomain": "news", + "username": "john@example.com" } -response = sg.client.subusers.post(request_body=data) -print response.status_code -print response.body -print response.headers +response = sg.client.whitelabel.domains.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## List all Subusers - -This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API. - -For more information about Subusers: - -* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html) -* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html) - -### GET /subusers +## List all domain authentications. +**This endpoint allows you to retrieve a list of all domain authentications you have created.** -```python -params = {'username': 'test_string', 'limit': 1, 'offset': 1} -response = sg.client.subusers.get(query_params=params) -print response.status_code -print response.body -print response.headers -``` -## Retrieve Subuser Reputations +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will effect your sender rating. +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -This endpoint allows you to request the reputations for your subusers. -### GET /subusers/reputations +### GET /whitelabel/domains ```python -params = {'usernames': 'test_string'} -response = sg.client.subusers.reputations.get(query_params=params) -print response.status_code -print response.body -print response.headers +params = {'username': 'test_string', 'domain': 'test_string', 'exclude_subusers': 'true', 'limit': 1, 'offset': 1} +response = sg.client.whitelabel.domains.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve email statistics for your subusers. +## Get the default domain authentication. -**This endpoint allows you to retrieve the email statistics for the given subusers.** +**This endpoint allows you to retrieve the default default authentication for a domain.** -You may retrieve statistics for up to 10 different subusers by including an additional _subusers_ parameter for each additional subuser. +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings. +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| domain | string |The domain to find a default domain authentication for. | -### GET /subusers/stats +### GET /whitelabel/domains/default ```python -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'subusers': 'test_string'} -response = sg.client.subusers.stats.get(query_params=params) -print response.status_code -print response.body -print response.headers +response = sg.client.whitelabel.domains.default.get() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve monthly stats for all subusers +## List the domain authentication associated with the given user. -**This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range.** +**This endpoint allows you to retrieve all of the domain authentications that have been assigned to a specific subuser.** -While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings. +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics: -`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`. +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools. -For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### GET /subusers/stats/monthly +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| username | string | Username of the subuser to find associated domain authentications for. | + +### GET /whitelabel/domains/subuser ```python -params = {'subuser': 'test_string', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'date': 'test_string', 'sort_by_direction': 'asc'} -response = sg.client.subusers.stats.monthly.get(query_params=params) -print response.status_code -print response.body -print response.headers +response = sg.client.whitelabel.domains.subuser.get() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve the totals for each email statistic metric for all subusers. +## Disassociate a domain authentication from a given user. -**This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range.** +**This endpoint allows you to disassociate a specific default authentication from a subuser.** +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings. +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools. -For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### GET /subusers/stats/sums +## URI Parameters +| URI Parameter | Type | Required? | Description | +|---|---|---|---| +| username | string | required | Username for the subuser to find associated domain authentications for. | + +### DELETE /whitelabel/domains/subuser ```python -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'} -response = sg.client.subusers.stats.sums.get(query_params=params) -print response.status_code -print response.body -print response.headers +response = sg.client.whitelabel.domains.subuser.delete() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Enable/disable a subuser +## Update a domain authentication. -This endpoint allows you to enable or disable a subuser. +**This endpoint allows you to update the settings for a domain authentication.** -For more information about Subusers: +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html) -* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html) +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### PATCH /subusers/{subuser_name} +### PATCH /whitelabel/domains/{domain_id} ```python data = { - "disabled": False + "custom_spf": True, + "default": False } -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).patch(request_body=data) -print response.status_code -print response.body -print response.headers +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Delete a subuser +## Retrieve a domain authentication. -This endpoint allows you to delete a subuser. This is a permanent action, once you delete a subuser it cannot be retrieved. +**This endpoint allows you to retrieve a specific domain authentication.** -For more information about Subusers: +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html) -* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html) +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### DELETE /subusers/{subuser_name} + +### GET /whitelabel/domains/{domain_id} ```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).delete() -print response.status_code -print response.body -print response.headers +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).get() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Update IPs assigned to a subuser +## Delete a domain authentication. -Each subuser should be assigned to an IP address, from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have their own, or multiple, IP addresses as well. +**This endpoint allows you to delete a domain authentication.** -More information: +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -* [How to request more IPs](https://sendgrid.com/docs/Classroom/Basics/Account/adding_an_additional_dedicated_ip_to_your_account.html) -* [IPs can be whitelabeled](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/ips.html) +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -### PUT /subusers/{subuser_name}/ips +### DELETE /whitelabel/domains/{domain_id} ```python -data = [ - "127.0.0.1" -] -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).ips.put(request_body=data) -print response.status_code -print response.body -print response.headers +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Update Monitor Settings for a subuser +## Associate a domain authentication with a given user. -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. +**This endpoint allows you to associate a specific domain authentication with a subuser.** -### PUT /subusers/{subuser_name}/monitor +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools. -```python -data = { - "email": "example@example.com", - "frequency": 500 -} -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.put(request_body=data) -print response.status_code -print response.body -print response.headers -``` -## Create monitor settings +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| domain_id | integer | ID of the domain authentication to associate with the subuser. | -### POST /subusers/{subuser_name}/monitor +### POST /whitelabel/domains/{domain_id}/subuser ```python data = { - "email": "example@example.com", - "frequency": 50000 + "username": "jane@example.com" } -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.post(request_body=data) -print response.status_code -print response.body -print response.headers +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve monitor settings for a subuser - -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. +## Add an IP to a domain authentication. -### GET /subusers/{subuser_name}/monitor +**This endpoint allows you to add an IP address to a domain authentication.** +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.get() -print response.status_code -print response.body -print response.headers -``` -## Delete monitor settings +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer | ID of the domain to which you are adding an IP | -### DELETE /subusers/{subuser_name}/monitor +### POST /whitelabel/domains/{id}/ips ```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.delete() -print response.status_code -print response.body -print response.headers +data = { + "ip": "192.168.0.1" +} +id = "test_url_param" +response = sg.client.whitelabel.domains._(id).ips.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve the monthly email statistics for a single subuser +## Remove an IP from a domain authentication. -**This endpoint allows you to retrieve the monthly email statistics for a specific subuser.** +**This endpoint allows you to remove a domain's IP address from that domain's authentication.** -While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings. +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics: -`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`. +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer | ID of the domain authentication to delete the IP from. | +| ip | string | IP to remove from the domain authentication. | -### GET /subusers/{subuser_name}/stats/monthly +### DELETE /whitelabel/domains/{id}/ips/{ip} ```python -params = {'date': 'test_string', 'sort_by_direction': 'asc', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1} -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params=params) -print response.status_code -print response.body -print response.headers +id = "test_url_param" +ip = "test_url_param" +response = sg.client.whitelabel.domains._(id).ips._(ip).delete() +print(response.status_code) +print(response.body) +print(response.headers) ``` - -# SUPPRESSION +## Validate a domain authentication. -## Retrieve all blocks +**This endpoint allows you to validate a domain authentication. If it fails, it will return an error message describing why the default authentication could not be validated.** -**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.** +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. -[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server. +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html) -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer |ID of the domain authentication to validate. | -### GET /suppression/blocks +### POST /whitelabel/domains/{id}/validate ```python -params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1} -response = sg.client.suppression.blocks.get(query_params=params) -print response.status_code -print response.body -print response.headers +id = "test_url_param" +response = sg.client.whitelabel.domains._(id).validate.post() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Delete blocks -**This endpoint allows you to delete all email addresses on your blocks list.** +## Create reverse DNS record -There are two options for deleting blocked emails: +**This endpoint allows you to create a reverse DNS record.** -1. You can delete all blocked emails by setting `delete_all` to true in the request body. -2. You can delete some blocked emails by specifying the email addresses in an array in the request body. +When creating a reverse DNS record, you should use the same subdomain that you used when you created a domain authentication. -[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server. +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). -### DELETE /suppression/blocks +### POST /whitelabel/ips ```python data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] + "domain": "example.com", + "ip": "192.168.1.1", + "subdomain": "email" } -response = sg.client.suppression.blocks.delete(request_body=data) -print response.status_code -print response.body -print response.headers +response = sg.client.whitelabel.ips.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve a specific block -**This endpoint allows you to retrieve a specific email address from your blocks list.** +## Retrieve all reverse DNS records -[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server. +**This endpoint allows you to retrieve all of the reverse DNS records that have been created by this account.** -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). +You may include a search key by using the "ip" parameter. This enables you to perform a prefix search for a given IP segment (e.g. "192."). -### GET /suppression/blocks/{email} +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). -```python -email = "test_url_param" -response = sg.client.suppression.blocks._(email).get() -print response.status_code -print response.body -print response.headers +### GET /whitelabel/ips + + +```python +params = {'ip': 'test_string', 'limit': 1, 'offset': 1} +response = sg.client.whitelabel.ips.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Delete a specific block +## Retrieve a reverse DNS record -**This endpoint allows you to delete a specific email address from your blocks list.** +**This endpoint allows you to retrieve a reverse DNS record.** -[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server. +A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). +For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html). -### DELETE /suppression/blocks/{email} +### GET /whitelabel/ips/{id} ```python -email = "test_url_param" -response = sg.client.suppression.blocks._(email).delete() -print response.status_code -print response.body -print response.headers +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).get() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve all bounces - -**This endpoint allows you to retrieve all of your bounces.** +## Delete a reverse DNS record -Bounces are messages that are returned to the server that sent it. +**This endpoint allows you to delete a reverse DNS record.** -For more information see: +A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. -* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information -* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html) +For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html). -### GET /suppression/bounces +### DELETE /whitelabel/ips/{id} ```python -params = {'start_time': 1, 'end_time': 1} -response = sg.client.suppression.bounces.get(query_params=params) -print response.status_code -print response.body -print response.headers +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).delete() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Delete bounces - -**This endpoint allows you to delete all of your bounces. You can also use this endpoint to remove a specific email address from your bounce list.** - -Bounces are messages that are returned to the server that sent it. +## Validate a reverse DNS record -For more information see: +**This endpoint allows you to validate a reverse DNS record.** -* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information -* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html) -* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html) +A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. -Note: the `delete_all` and `emails` parameters should be used independently of each other as they have different purposes. +For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html). -### DELETE /suppression/bounces +### POST /whitelabel/ips/{id}/validate ```python -data = { - "delete_all": True, - "emails": [ - "example@example.com", - "example2@example.com" - ] -} -response = sg.client.suppression.bounces.delete(request_body=data) -print response.status_code -print response.body -print response.headers +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).validate.post() +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve a Bounce +## Create a Link Branding -**This endpoint allows you to retrieve a specific bounce for a given email address.** - -Bounces are messages that are returned to the server that sent it. +**This endpoint allows you to create a new link branding.** -For more information see: +Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. -* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information -* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html) -* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html) +For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html). -### GET /suppression/bounces/{email} +### POST /whitelabel/links ```python -email = "test_url_param" -response = sg.client.suppression.bounces._(email).get() -print response.status_code -print response.body -print response.headers +data = { + "default": True, + "domain": "example.com", + "subdomain": "mail" +} +params = {'limit': 1, 'offset': 1} +response = sg.client.whitelabel.links.post(request_body=data, query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Delete a bounce +## Retrieve all link brandings -**This endpoint allows you to remove an email address from your bounce list.** - -Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email address from your bounce list. +**This endpoint allows you to retrieve all link brandings.** -For more information see: +Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. -* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information -* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html) -* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html) +For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html). -### DELETE /suppression/bounces/{email} +### GET /whitelabel/links ```python -params = {'email_address': 'example@example.com'} -email = "test_url_param" -response = sg.client.suppression.bounces._(email).delete(query_params=params) -print response.status_code -print response.body -print response.headers +params = {'limit': 1} +response = sg.client.whitelabel.links.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) ``` -## Retrieve all invalid emails +## Retrieve a Default Link Branding -**This endpoint allows you to retrieve a list of all invalid email addresses.** +**This endpoint allows you to retrieve the default link branding.** -An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server. +Default link branding is the actual link branding to be used when sending messages. If there are multiple link brandings, the default is determined by the following order: +Check out our spring line!
", - "ip_pool": "marketing", - "list_ids": [ - 110, - 124 - ], - "plain_content": "Check out our spring line!", - "segment_ids": [ - 110 - ], - "sender_id": 124451, - "subject": "New Products for Spring!", - "suppression_group_id": 42, - "title": "March Newsletter" + "categories": [ + "spring line" + ], + "custom_unsubscribe_url": "", + "html_content": "Check out our spring line!
", + "ip_pool": "marketing", + "list_ids": [ + 110, + 124 + ], + "plain_content": "Check out our spring line!", + "segment_ids": [ + 110 + ], + "sender_id": 124451, + "subject": "New Products for Spring!", + "suppression_group_id": 42, + "title": "March Newsletter" } response = sg.client.campaigns.post(request_body=data) print(response.status_code) @@ -49,13 +48,13 @@ # PATCH /campaigns/{campaign_id} # data = { - "categories": [ - "summer line" - ], - "html_content": "Check out our summer line!
", - "plain_content": "Check out our summer line!", - "subject": "New Products for Summer!", - "title": "May Newsletter" + "categories": [ + "summer line" + ], + "html_content": "Check out our summer line!
", + "plain_content": "Check out our summer line!", + "subject": "New Products for Summer!", + "title": "May Newsletter" } campaign_id = "test_url_param" response = sg.client.campaigns._(campaign_id).patch(request_body=data) @@ -88,10 +87,11 @@ # PATCH /campaigns/{campaign_id}/schedules # data = { - "send_at": 1489451436 + "send_at": 1489451436 } campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.patch(request_body=data) +response = sg.client.campaigns._( + campaign_id).schedules.patch(request_body=data) print(response.status_code) print(response.body) print(response.headers) @@ -101,7 +101,7 @@ # POST /campaigns/{campaign_id}/schedules # data = { - "send_at": 1489771528 + "send_at": 1489771528 } campaign_id = "test_url_param" response = sg.client.campaigns._(campaign_id).schedules.post(request_body=data) @@ -144,11 +144,11 @@ # POST /campaigns/{campaign_id}/schedules/test # data = { - "to": "your.email@example.com" + "to": "your.email@example.com" } campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body=data) +response = sg.client.campaigns._( + campaign_id).schedules.test.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/categories/categories.py b/examples/categories/categories.py index 7984f0fe0..b8275713f 100644 --- a/examples/categories/categories.py +++ b/examples/categories/categories.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve all categories # @@ -19,7 +18,8 @@ # Retrieve Email Statistics for Categories # # GET /categories/stats # -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'categories': 'test_string'} +params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, + 'offset': 1, 'start_date': '2016-01-01', 'categories': 'test_string'} response = sg.client.categories.stats.get(query_params=params) print(response.status_code) print(response.body) @@ -29,9 +29,14 @@ # Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] # # GET /categories/stats/sums # -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'} +params = {'end_date': '2016-04-01', + 'aggregated_by': 'day', + 'limit': 1, + 'sort_by_metric': 'test_string', + 'offset': 1, + 'start_date': '2016-01-01', + 'sort_by_direction': 'asc'} response = sg.client.categories.stats.sums.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/clients/clients.py b/examples/clients/clients.py index 7831ef78f..023a440db 100644 --- a/examples/clients/clients.py +++ b/examples/clients/clients.py @@ -1,15 +1,16 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve email statistics by client type. # # GET /clients/stats # -params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'} +params = {'aggregated_by': 'day', + 'start_date': '2016-01-01', + 'end_date': '2016-04-01'} response = sg.client.clients.stats.get(query_params=params) print(response.status_code) print(response.body) @@ -19,10 +20,11 @@ # Retrieve stats by a specific client type. # # GET /clients/{client_type}/stats # -params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'} +params = {'aggregated_by': 'day', + 'start_date': '2016-01-01', + 'end_date': '2016-04-01'} client_type = "test_url_param" response = sg.client.clients._(client_type).stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/contactdb/contactdb.py b/examples/contactdb/contactdb.py index c234d7724..b702974df 100644 --- a/examples/contactdb/contactdb.py +++ b/examples/contactdb/contactdb.py @@ -1,17 +1,16 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Create a Custom Field # # POST /contactdb/custom_fields # data = { - "name": "pet", - "type": "text" + "name": "pet", + "type": "text" } response = sg.client.contactdb.custom_fields.post(request_body=data) print(response.status_code) @@ -52,7 +51,7 @@ # POST /contactdb/lists # data = { - "name": "your list name" + "name": "your list name" } response = sg.client.contactdb.lists.post(request_body=data) print(response.status_code) @@ -73,10 +72,10 @@ # DELETE /contactdb/lists # data = [ - 1, - 2, - 3, - 4 + 1, + 2, + 3, + 4 ] response = sg.client.contactdb.lists.delete(request_body=data) print(response.status_code) @@ -88,11 +87,13 @@ # PATCH /contactdb/lists/{list_id} # data = { - "name": "newlistname" + "name": "newlistname" } params = {'list_id': 1} list_id = "test_url_param" -response = sg.client.contactdb.lists._(list_id).patch(request_body=data, query_params=params) +response = sg.client.contactdb.lists._(list_id).patch( + request_body=data, + query_params=params) print(response.status_code) print(response.body) print(response.headers) @@ -124,11 +125,12 @@ # POST /contactdb/lists/{list_id}/recipients # data = [ - "recipient_id1", - "recipient_id2" + "recipient_id1", + "recipient_id2" ] list_id = "test_url_param" -response = sg.client.contactdb.lists._(list_id).recipients.post(request_body=data) +response = sg.client.contactdb.lists._( + list_id).recipients.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) @@ -139,7 +141,8 @@ params = {'page': 1, 'page_size': 1} list_id = "test_url_param" -response = sg.client.contactdb.lists._(list_id).recipients.get(query_params=params) +response = sg.client.contactdb.lists._( + list_id).recipients.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) @@ -150,7 +153,8 @@ list_id = "test_url_param" recipient_id = "test_url_param" -response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post() +response = sg.client.contactdb.lists._( + list_id).recipients._(recipient_id).post() print(response.status_code) print(response.body) print(response.headers) @@ -162,7 +166,8 @@ params = {'recipient_id': 1, 'list_id': 1} list_id = "test_url_param" recipient_id = "test_url_param" -response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params=params) +response = sg.client.contactdb.lists._(list_id).recipients._( + recipient_id).delete(query_params=params) print(response.status_code) print(response.body) print(response.headers) @@ -172,11 +177,11 @@ # PATCH /contactdb/recipients # data = [ - { - "email": "jones@example.com", - "first_name": "Guy", - "last_name": "Jones" - } + { + "email": "jones@example.com", + "first_name": "Guy", + "last_name": "Jones" + } ] response = sg.client.contactdb.recipients.patch(request_body=data) print(response.status_code) @@ -188,18 +193,18 @@ # POST /contactdb/recipients # data = [ - { - "age": 25, - "email": "example@example.com", - "first_name": "", - "last_name": "User" - }, - { - "age": 25, - "email": "example2@example.com", - "first_name": "Example", - "last_name": "User" - } + { + "age": 25, + "email": "example@example.com", + "first_name": "", + "last_name": "User" + }, + { + "age": 25, + "email": "example2@example.com", + "first_name": "Example", + "last_name": "User" + } ] response = sg.client.contactdb.recipients.post(request_body=data) print(response.status_code) @@ -221,8 +226,8 @@ # DELETE /contactdb/recipients # data = [ - "recipient_id1", - "recipient_id2" + "recipient_id1", + "recipient_id2" ] response = sg.client.contactdb.recipients.delete(request_body=data) print(response.status_code) @@ -301,28 +306,28 @@ # POST /contactdb/segments # data = { - "conditions": [ - { - "and_or": "", - "field": "last_name", - "operator": "eq", - "value": "Miller" - }, - { - "and_or": "and", - "field": "last_clicked", - "operator": "gt", - "value": "01/02/2015" - }, - { - "and_or": "or", - "field": "clicks.campaign_identifier", - "operator": "eq", - "value": "513" - } - ], - "list_id": 4, - "name": "Last Name Miller" + "conditions": [ + { + "and_or": "", + "field": "last_name", + "operator": "eq", + "value": "Miller" + }, + { + "and_or": "and", + "field": "last_clicked", + "operator": "gt", + "value": "01/02/2015" + }, + { + "and_or": "or", + "field": "clicks.campaign_identifier", + "operator": "eq", + "value": "513" + } + ], + "list_id": 4, + "name": "Last Name Miller" } response = sg.client.contactdb.segments.post(request_body=data) print(response.status_code) @@ -343,20 +348,22 @@ # PATCH /contactdb/segments/{segment_id} # data = { - "conditions": [ - { - "and_or": "", - "field": "last_name", - "operator": "eq", - "value": "Miller" - } - ], - "list_id": 5, - "name": "The Millers" + "conditions": [ + { + "and_or": "", + "field": "last_name", + "operator": "eq", + "value": "Miller" + } + ], + "list_id": 5, + "name": "The Millers" } params = {'segment_id': 'test_string'} segment_id = "test_url_param" -response = sg.client.contactdb.segments._(segment_id).patch(request_body=data, query_params=params) +response = sg.client.contactdb.segments._(segment_id).patch( + request_body=data, + query_params=params) print(response.status_code) print(response.body) print(response.headers) @@ -378,7 +385,8 @@ params = {'delete_contacts': 'true'} segment_id = "test_url_param" -response = sg.client.contactdb.segments._(segment_id).delete(query_params=params) +response = sg.client.contactdb.segments._( + segment_id).delete(query_params=params) print(response.status_code) print(response.body) print(response.headers) @@ -389,8 +397,8 @@ params = {'page': 1, 'page_size': 1} segment_id = "test_url_param" -response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params=params) +response = sg.client.contactdb.segments._( + segment_id).recipients.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/dataresidency/set_region.py b/examples/dataresidency/set_region.py new file mode 100644 index 000000000..9aae2611f --- /dev/null +++ b/examples/dataresidency/set_region.py @@ -0,0 +1,37 @@ +import sendgrid +import os + +from sendgrid import Email, To, Content, Mail + +# Example 1 +# setting region to be "global" + +sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) +from_email = Email("example@abc.com") +to_email = To("example@abc.com") +subject = "Sending with SendGrid is Fun" +content = Content("text/plain", "and easy to do anywhere, even with Python") +mail = Mail(from_email, to_email, subject, content) +sg.set_sendgrid_data_residency("global") +print(sg.client.host) +response = sg.client.mail.send.post(request_body=mail.get()) +print(response) +print(response.status_code) +print(response.body) +print(response.headers) + +# Example 2 +# setting region to "eu" +sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY_EU')) +sg.set_sendgrid_data_residency("eu") +from_email = Email("example@abc.com") +to_email = To("example@abc.com") +subject = "Sending with SendGrid is Fun" +content = Content("text/plain", "and easy to do anywhere, even with Python") +print(sg.client.host) +mail = Mail(from_email, to_email, subject, content) +response = sg.client.mail.send.post(request_body=mail.get()) +print(response) +print(response.status_code) +print(response.body) +print(response.headers) \ No newline at end of file diff --git a/examples/devices/devices.py b/examples/devices/devices.py index 108e98452..50c96243d 100644 --- a/examples/devices/devices.py +++ b/examples/devices/devices.py @@ -1,17 +1,18 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve email statistics by device type. # # GET /devices/stats # -params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1} +params = {'aggregated_by': 'day', 'limit': 1, + 'start_date': '2016-01-01', + 'end_date': '2016-04-01', + 'offset': 1} response = sg.client.devices.stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/geo/geo.py b/examples/geo/geo.py index 7d58ec085..64265b201 100644 --- a/examples/geo/geo.py +++ b/examples/geo/geo.py @@ -1,17 +1,20 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve email statistics by country and state/province. # # GET /geo/stats # -params = {'end_date': '2016-04-01', 'country': 'US', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'} +params = {'end_date': '2016-04-01', + 'country': 'US', + 'aggregated_by': 'day', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01'} response = sg.client.geo.stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/helpers/README.md b/examples/helpers/README.md new file mode 100644 index 000000000..8d7594d44 --- /dev/null +++ b/examples/helpers/README.md @@ -0,0 +1,73 @@ +## Using helper class to send emails +You can use helper classes to customize the process of sending emails using SendGrid. Each process (such as sending a mock email, +building attachments, configuring settings, building personalizations, etc.) are made easy using helpers. All you need is a file with +all the classes imported and you can start sending emails! + +> Note: You will need move this file to the root directory of this project to execute properly. + +### Creating a simple email object and sending it +The example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L9) +defines minimum requirement to send an email. +``` + from_email = Email("test@example.com") + subject = "Hello World from the SendGrid Python Library" + to_email = Email("test@example.com") +``` +You can use `Email` class to define a mail id. + +``` +content = Content("text/plain", "some text here") +``` +The `Content` class takes mainly two parameters: MIME type and the actual content of the email, it then returns the JSON-ready representation of this content. + +``` + mail = Mail(from_email, to_email, subject, content) +``` +After adding the above we create a mail object using `Mail` class, it takes the following parameters: email address to send from, subject line of emails, email address to send to, content of the message. +For more information on parameters and usage, see [here](../mail/mail.py) + +### Creating Personalizations + +The personalization helper can be used to create personalizations and customize various aspects of an email. See example [here](mail_example.py) in `build_multiple_emails_personalized()`, and refer [here](https://docs.sendgrid.com/for-developers/sending-email/personalizations) for more documentation. +``` + mock_personalization = Personalization() + + for to_addr in personalization['to_list']: + mock_personalization.add_to(to_addr) + + mock_personalization.set_from(from_addr) + mock_personalization.add_cc(cc_addr) + # etc... +``` + +### Creating Attachments + +To create attachments, we use the `Attachment` class and make sure the content is base64 encoded before passing it into attachment.content. +``` + attachment = Attachment() + attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" + "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") +``` +Another example: [Link](../../use_cases/attachment.md) + +### Managing Settings + +To configure settings in mail, you can use the `MailSettings` class. The class takes some [parameters](../mailsettings/mailsettings.py#L1)(such as bcc_settings, bypass_list_management, footer_settings, sandbox_mode) + +To add tracking settings, you can add `TrackingSettings` class. See example [here](mail_example.py#L118) and parameters and usage [here](../trackingsettings/trackingsettings.py). + +### Sending email + +After you have configured every component and added your own functions, you can send emails. +``` + sg = SendGridAPIClient() + data = build_kitchen_sink() + response = sg.send(data) +``` +Make sure you have [environment variable](../../TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key) set up! +Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L203). + +### Using Dynamic Templates +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. + +See Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L221). diff --git a/examples/helpers/eventwebhook/eventwebhook_example.py b/examples/helpers/eventwebhook/eventwebhook_example.py new file mode 100644 index 000000000..91ad8d64b --- /dev/null +++ b/examples/helpers/eventwebhook/eventwebhook_example.py @@ -0,0 +1,14 @@ +from sendgrid.helpers.eventwebhook import EventWebhook, EventWebhookHeader + +def is_valid_signature(request): + public_key = 'base64-encoded public key' + + event_webhook = EventWebhook() + ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key) + + return event_webhook.verify_signature( + request.text, + request.headers[EventWebhookHeader.SIGNATURE], + request.headers[EventWebhookHeader.TIMESTAMP], + ec_public_key + ) diff --git a/examples/helpers/mail/mail_example.py b/examples/helpers/mail/mail_example.py deleted file mode 100644 index bfd8ea718..000000000 --- a/examples/helpers/mail/mail_example.py +++ /dev/null @@ -1,219 +0,0 @@ -import json -import os -import urllib2 -from sendgrid.helpers.mail import * -from sendgrid import * - -# NOTE: you will need move this file to the root -# directory of this project to execute properly. - - -def build_hello_email(): - """Minimum required to send an email""" - from_email = Email("test@example.com") - subject = "Hello World from the SendGrid Python Library" - to_email = Email("test@example.com") - content = Content("text/plain", "some text here") - mail = Mail(from_email, subject, to_email, content) - mail.personalizations[0].add_to(Email("test2@example.com")) - - return mail.get() - - -def build_personalization(personalization): - """Build personalization mock instance from a mock dict""" - mock_personalization = Personalization() - for to_addr in personalization['to_list']: - personalization.add_to(to_addr) - - for cc_addr in personalization['cc_list']: - personalization.add_to(cc_addr) - - for bcc_addr in personalization['bcc_list']: - personalization.add_bc(bcc_addr) - - for header in personalization['headers']: - personalization.add_header(header) - - for substitution in personalization['substitutions']: - personalization.add_substitution(substitution) - - for arg in personalization['custom_args']: - personalization.add_custom_arg(arg) - - personalization.subject = personalization['subject'] - personalization.send_at = personalization['send_at'] - return mock_personalization - - -def get_mock_personalization_dict(): - """Get a dict of personalization mock.""" - mock_pers = dict() - - mock_pers['to_list'] = [Email("test1@example.com", - "Example User"), - Email("test2@example.com", - "Example User")] - - mock_pers['cc_list'] = [Email("test3@example.com", - "Example User"), - Email("test4@example.com", - "Example User")] - - mock_pers['bcc_list'] = [Email("test5@example.com"), - Email("test6@example.com")] - - mock_pers['subject'] = ("Hello World from the Personalized " - "SendGrid Python Library") - - mock_pers['headers'] = [Header("X-Test", "test"), - Header("X-Mock", "true")] - - mock_pers['substitutions'] = [Substitution("%name%", "Example User"), - Substitution("%city%", "Denver")] - - mock_pers['custom_args'] = [CustomArg("user_id", "343"), - CustomArg("type", "marketing")] - - mock_pers['send_at'] = 1443636843 - return mock_pers - - -def build_attachment1(): - """Build attachment mock.""" - attachment = Attachment() - attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" - "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") - attachment.type = "application/pdf" - attachment.filename = "balance_001.pdf" - attachment.disposition = "attachment" - attachment.content_id = "Balance Sheet" - return attachment - - -def build_attachment2(): - """Build attachment mock.""" - attachment = Attachment() - attachment.content = "BwdW" - attachment.type = "image/png" - attachment.filename = "banner.png" - attachment.disposition = "inline" - attachment.content_id = "Banner" - return attachment - - -def build_mail_settings(): - """Build mail settings mock.""" - mail_settings = MailSettings() - mail_settings.bcc_settings = BCCSettings(True, Email("test@example.com")) - mail_settings.bypass_list_management = BypassListManagement(True) - mail_settings.footer_settings = FooterSettings(True, "Footer Text", - ("Footer " - "Text")) - mail_settings.sandbox_mode = SandBoxMode(True) - mail_settings.spam_check = SpamCheck(True, 1, - "https://spamcatcher.sendgrid.com") - return mail_settings - - -def build_tracking_settings(): - """Build tracking settings mock.""" - tracking_settings = TrackingSettings() - tracking_settings.click_tracking = ClickTracking(True, True) - tracking_settings.open_tracking = OpenTracking(True, - ("Optional tag to " - "replace with the" - "open image in the " - "body of the message")) - - subs_track = SubscriptionTracking(True, - ("text to insert into the " - "text/plain portion of the" - " message"), - ("html to insert " - "into the text/html portion of " - "the message"), - ("Optional tag to replace with " - "the open image in the body of " - "the message")) - - tracking_settings.subscription_tracking = subs_track - tracking_settings.ganalytics = Ganalytics(True, "some source", - "some medium", "some term", - "some_content", "some_campaign") - return tracking_settings - - -def build_kitchen_sink(): - """All settings set""" - mail = Mail() - - mail.from_email = Email("test@example.com", "Example User") - mail.subject = "Hello World from the SendGrid Python Library" - - personalization = get_mock_personalization_dict() - mail.add_personalization(build_personalization(personalization)) - mail.add_personalization(build_personalization(personalization)) - - mail.add_content(Content("text/plain", "some text here")) - mail.add_content(Content("text/html", ("some text " - "here"))) - - mail.add_attachment(build_attachment1()) - mail.add_attachment(build_attachment2()) - - mail.template_id = "13b8f94f-bcae-4ec6-b752-70d6cb59f932" - - mail.add_section(Section("%section1%", "Substitution Text for Section 1")) - mail.add_section(Section("%section2%", "Substitution Text for Section 2")) - - mail.add_header(Header("X-Test1", "test1")) - mail.add_header(Header("X-Test3", "test2")) - - mail.add_category(Category("May")) - mail.add_category(Category("2016")) - - mail.add_custom_arg(CustomArg("campaign", "welcome")) - mail.add_custom_arg(CustomArg("weekday", "morning")) - - mail.send_at = 1443636842 - - # This must be a valid [batch ID] - # (https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work - # mail.set_batch_id("N2VkYjBjYWItMGU4OC0xMWU2LWJhMzYtZjQ1Yzg5OTBkNzkxLWM5ZTUyZjNhOA") - mail.asm = ASM(99, [4, 5, 6, 7, 8]) - mail.ip_pool_name = "24" - mail.mail_settings = build_mail_settings() - mail.tracking_settings = build_tracking_settings() - mail.reply_to = Email("test@example.com") - - return mail.get() - - -def send_hello_email(): - # Assumes you set your environment variable: - # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key - sg = SendGridAPIClient() - data = build_hello_email() - response = sg.client.mail.send.post(request_body=data) - print(response.status_code) - print(response.headers) - print(response.body) - - -def send_kitchen_sink(): - # Assumes you set your environment variable: - # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key - sg = SendGridAPIClient() - data = build_kitchen_sink() - response = sg.client.mail.send.post(request_body=data) - print(response.status_code) - print(response.headers) - print(response.body) - - -# this will actually send an email -send_hello_email() - -# this will only send an email if you set SandBox Mode to False -send_kitchen_sink() diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py new file mode 100644 index 000000000..f6905787b --- /dev/null +++ b/examples/helpers/mail_example.py @@ -0,0 +1,382 @@ +import os +import json + +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import * + + +# NOTE: you will need move this file to the root +# directory of this project to execute properly. + + +def build_hello_email(): + ## Send a Single Email to a Single Recipient + + message = Mail(from_email=From('from@example.com', 'Example From Name'), + to_emails=To('to@example.com', 'Example To Name'), + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + + try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + return message.get() + + except SendGridException as e: + print(e.message) + + mock_personalization = Personalization() + personalization_dict = get_mock_personalization_dict() + + for cc_addr in personalization_dict['cc_list']: + mock_personalization.add_to(cc_addr) + + for bcc_addr in personalization_dict['bcc_list']: + mock_personalization.add_bcc(bcc_addr) + + for header in personalization_dict['headers']: + mock_personalization.add_header(header) + + for substitution in personalization_dict['substitutions']: + mock_personalization.add_substitution(substitution) + + for arg in personalization_dict['custom_args']: + mock_personalization.add_custom_arg(arg) + + mock_personalization.subject = personalization_dict['subject'] + mock_personalization.send_at = personalization_dict['send_at'] + + message.add_personalization(mock_personalization) + + return message + +def get_mock_personalization_dict(): + """Get a dict of personalization mock.""" + mock_pers = dict() + + mock_pers['to_list'] = [To("test1@example.com", + "Example User"), + To("test2@example.com", + "Example User")] + + mock_pers['cc_list'] = [To("test3@example.com", + "Example User"), + To("test4@example.com", + "Example User")] + + mock_pers['bcc_list'] = [To("test5@example.com"), + To("test6@example.com")] + + mock_pers['subject'] = ("Hello World from the Personalized " + "SendGrid Python Library") + + mock_pers['headers'] = [Header("X-Test", "test"), + Header("X-Mock", "true")] + + mock_pers['substitutions'] = [Substitution("%name%", "Example User"), + Substitution("%city%", "Denver")] + + mock_pers['custom_args'] = [CustomArg("user_id", "343"), + CustomArg("type", "marketing")] + + mock_pers['send_at'] = 1443636843 + return mock_pers + +def build_multiple_emails_personalized(): + # Note that the domain for all From email addresses must match + + message = Mail(from_email=From('from@example.com', 'Example From Name'), + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + + mock_personalization = Personalization() + mock_personalization.add_to(To('test@example.com', 'Example User 1')) + mock_personalization.add_cc(Cc('test1@example.com', 'Example User 2')) + message.add_personalization(mock_personalization) + + mock_personalization_2 = Personalization() + mock_personalization_2.add_to(To('test2@example.com', 'Example User 3')) + mock_personalization_2.set_from(From('from@example.com', 'Example From Name 2')) + mock_personalization_2.add_bcc(Bcc('test3@example.com', 'Example User 4')) + message.add_personalization(mock_personalization_2) + + try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + return message.get() + + except SendGridException as e: + print(e.message) + + return message + +def build_attachment1(): + """Build attachment mock. Make sure your content is base64 encoded before passing into attachment.content. + Another example: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/attachment.md""" + + attachment = Attachment() + attachment.file_content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" + "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") + attachment.file_type = "application/pdf" + attachment.file_name = "balance_001.pdf" + attachment.disposition = "attachment" + attachment.content_id = "Balance Sheet" + return attachment + + +def build_attachment2(): + """Build attachment mock.""" + attachment = Attachment() + attachment.file_content = "BwdW" + attachment.file_type = "image/png" + attachment.file_name = "banner.png" + attachment.disposition = "inline" + attachment.content_id = "Banner" + return attachment + +def build_kitchen_sink(): + """All settings set""" + from sendgrid.helpers.mail import ( + Mail, From, To, Cc, Bcc, Subject, PlainTextContent, + HtmlContent, SendGridException, Substitution, + Header, CustomArg, SendAt, Content, MimeType, Attachment, + FileName, FileContent, FileType, Disposition, ContentId, + TemplateId, Section, ReplyTo, Category, BatchId, Asm, + GroupId, GroupsToDisplay, IpPoolName, MailSettings, + BccSettings, BccSettingsEmail, BypassListManagement, + FooterSettings, FooterText, FooterHtml, SandBoxMode, + SpamCheck, SpamThreshold, SpamUrl, TrackingSettings, + ClickTracking, SubscriptionTracking, SubscriptionText, + SubscriptionHtml, SubscriptionSubstitutionTag, + OpenTracking, OpenTrackingSubstitutionTag, Ganalytics, + UtmSource, UtmMedium, UtmTerm, UtmContent, UtmCampaign) + import time + import datetime + + message = Mail() + + # Define Personalizations + + message.to = To('test1@sendgrid.com', 'Example User1', p=0) + message.to = [ + To('test2@sendgrid.com', 'Example User2', p=0), + To('test3@sendgrid.com', 'Example User3', p=0) + ] + + message.cc = Cc('test4@example.com', 'Example User4', p=0) + message.cc = [ + Cc('test5@example.com', 'Example User5', p=0), + Cc('test6@example.com', 'Example User6', p=0) + ] + + message.bcc = Bcc('test7@example.com', 'Example User7', p=0) + message.bcc = [ + Bcc('test8@example.com', 'Example User8', p=0), + Bcc('test9@example.com', 'Example User9', p=0) + ] + + message.subject = Subject('Sending with SendGrid is Fun 0', p=0) + + message.header = Header('X-Test1', 'Test1', p=0) + message.header = Header('X-Test2', 'Test2', p=0) + message.header = [ + Header('X-Test3', 'Test3', p=0), + Header('X-Test4', 'Test4', p=0) + ] + + message.substitution = Substitution('%name1%', 'Example Name 1', p=0) + message.substitution = Substitution('%city1%', 'Example City 1', p=0) + message.substitution = [ + Substitution('%name2%', 'Example Name 2', p=0), + Substitution('%city2%', 'Example City 2', p=0) + ] + + message.custom_arg = CustomArg('marketing1', 'true', p=0) + message.custom_arg = CustomArg('transactional1', 'false', p=0) + message.custom_arg = [ + CustomArg('marketing2', 'false', p=0), + CustomArg('transactional2', 'true', p=0) + ] + + message.send_at = SendAt(1461775051, p=0) + + message.to = To('test10@example.com', 'Example User10', p=1) + message.to = [ + To('test11@example.com', 'Example User11', p=1), + To('test12@example.com', 'Example User12', p=1) + ] + + message.cc = Cc('test13@example.com', 'Example User13', p=1) + message.cc = [ + Cc('test14@example.com', 'Example User14', p=1), + Cc('test15@example.com', 'Example User15', p=1) + ] + + message.bcc = Bcc('test16@example.com', 'Example User16', p=1) + message.bcc = [ + Bcc('test17@example.com', 'Example User17', p=1), + Bcc('test18@example.com', 'Example User18', p=1) + ] + + message.header = Header('X-Test5', 'Test5', p=1) + message.header = Header('X-Test6', 'Test6', p=1) + message.header = [ + Header('X-Test7', 'Test7', p=1), + Header('X-Test8', 'Test8', p=1) + ] + + message.substitution = Substitution('%name3%', 'Example Name 3', p=1) + message.substitution = Substitution('%city3%', 'Example City 3', p=1) + message.substitution = [ + Substitution('%name4%', 'Example Name 4', p=1), + Substitution('%city4%', 'Example City 4', p=1) + ] + + message.custom_arg = CustomArg('marketing3', 'true', p=1) + message.custom_arg = CustomArg('transactional3', 'false', p=1) + message.custom_arg = [ + CustomArg('marketing4', 'false', p=1), + CustomArg('transactional4', 'true', p=1) + ] + + message.send_at = SendAt(1461775052, p=1) + + message.subject = Subject('Sending with SendGrid is Fun 1', p=1) + + # The values below this comment are global to entire message + + message.from_email = From('help@twilio.com', 'Twilio SendGrid') + + message.reply_to = ReplyTo('help_reply@twilio.com', 'Twilio SendGrid Reply') + + message.subject = Subject('Sending with SendGrid is Fun 2') + + message.content = Content(MimeType.text, 'and easy to do anywhere, even with Python') + message.content = Content(MimeType.html, 'and easy to do anywhere, even with Python') + message.content = [ + Content('text/calendar', 'Party Time!!'), + Content('text/custom', 'Party Time 2!!') + ] + + message.attachment = Attachment(FileContent('base64 encoded content 1'), + FileName('balance_001.pdf'), + FileType('application/pdf'), + Disposition('attachment'), + ContentId('Content ID 1')) + message.attachment = [ + Attachment(FileContent('base64 encoded content 2'), + FileName('banner.png'), + FileType('image/png'), + Disposition('inline'), + ContentId('Content ID 2')), + Attachment(FileContent('base64 encoded content 3'), + FileName('banner2.png'), + FileType('image/png'), + Disposition('inline'), + ContentId('Content ID 3')) + ] + + message.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932') + + message.section = Section('%section1%', 'Substitution for Section 1 Tag') + message.section = [ + Section('%section2%', 'Substitution for Section 2 Tag'), + Section('%section3%', 'Substitution for Section 3 Tag') + ] + + message.header = Header('X-Test9', 'Test9') + message.header = Header('X-Test10', 'Test10') + message.header = [ + Header('X-Test11', 'Test11'), + Header('X-Test12', 'Test12') + ] + + message.category = Category('Category 1') + message.category = Category('Category 2') + message.category = [ + Category('Category 1'), + Category('Category 2') + ] + + message.custom_arg = CustomArg('marketing5', 'false') + message.custom_arg = CustomArg('transactional5', 'true') + message.custom_arg = [ + CustomArg('marketing6', 'true'), + CustomArg('transactional6', 'false') + ] + + message.send_at = SendAt(1461775053) + + message.batch_id = BatchId("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi") + + message.asm = Asm(GroupId(1), GroupsToDisplay([1,2,3,4])) + + message.ip_pool_name = IpPoolName("IP Pool Name") + + mail_settings = MailSettings() + mail_settings.bcc_settings = BccSettings(False, BccSettingsTo("bcc@twilio.com")) + mail_settings.bypass_list_management = BypassListManagement(False) + mail_settings.footer_settings = FooterSettings(True, FooterText("w00t"), FooterHtml("Hello, world!
ThanksThe SendGrid Team
", - "text": "Thanks,/n The SendGrid Team" - }, - "sandbox_mode": { - "enable": False - }, - "spam_check": { - "enable": True, - "post_to_url": "http://example.com/compliance", - "threshold": 3 - } - }, - "personalizations": [ - { - "bcc": [ + "asm": { + "group_id": 1, + "groups_to_display": [ + 1, + 2, + 3 + ] + }, + "attachments": [ { - "email": "sam.doe@example.com", - "name": "Sam Doe" + "content": "[BASE64 encoded content block here]", + "content_id": "ii_139db99fdb5c3704", + "disposition": "inline", + "filename": "file1.jpg", + "name": "file1", + "type": "jpg" } - ], - "cc": [ + ], + "batch_id": "[YOUR BATCH ID GOES HERE]", + "categories": [ + "category1", + "category2" + ], + "content": [ { - "email": "jane.doe@example.com", - "name": "Jane Doe" + "type": "text/html", + "value": "Hello, world!
ThanksThe SendGrid Team
", + "text": "Thanks,/n The SendGrid Team" + }, + "sandbox_mode": { + "enable": False + }, + "spam_check": { + "enable": True, + "post_to_url": "http://example.com/compliance", + "threshold": 3 + } + }, + "personalizations": [ { - "email": "john.doe@example.com", - "name": "John Doe" + "bcc": [ + { + "email": "sam.doe@example.com", + "name": "Sam Doe" + } + ], + "cc": [ + { + "email": "jane.doe@example.com", + "name": "Jane Doe" + } + ], + "custom_args": { + "New Argument 1": "New Value 1", + "activationAttempt": "1", + "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]" + }, + "headers": { + "X-Accept-Language": "en", + "X-Mailer": "MyApp" + }, + "send_at": 1409348513, + "subject": "Hello, World!", + "substitutions": { + "id": "substitutions", + "type": "object" + }, + "to": [ + { + "email": "john.doe@example.com", + "name": "John Doe" + } + ] + } + ], + "reply_to": { + "email": "sam.smith@example.com", + "name": "Sam Smith" + }, + "sections": { + "section": { + ":sectionName1": "section 1 text", + ":sectionName2": "section 2 text" + } + }, + "send_at": 1409348513, + "subject": "Hello, World!", + "template_id": "[YOUR TEMPLATE ID GOES HERE]", + "tracking_settings": { + "click_tracking": { + "enable": True, + "enable_text": True + }, + "ganalytics": { + "enable": True, + "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]", + "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]", + "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]", + "utm_name": "[NAME OF YOUR CAMPAIGN]", + "utm_term": "[IDENTIFY PAID KEYWORDS HERE]" + }, + "open_tracking": { + "enable": True, + "substitution_tag": "%opentrack" + }, + "subscription_tracking": { + "enable": True, + "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.", + "substitution_tag": "<%click here%>", + "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>." } - ] - } - ], - "reply_to": { - "email": "sam.smith@example.com", - "name": "Sam Smith" - }, - "sections": { - "section": { - ":sectionName1": "section 1 text", - ":sectionName2": "section 2 text" - } - }, - "send_at": 1409348513, - "subject": "Hello, World!", - "template_id": "[YOUR TEMPLATE ID GOES HERE]", - "tracking_settings": { - "click_tracking": { - "enable": True, - "enable_text": True - }, - "ganalytics": { - "enable": True, - "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]", - "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]", - "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]", - "utm_name": "[NAME OF YOUR CAMPAIGN]", - "utm_term": "[IDENTIFY PAID KEYWORDS HERE]" - }, - "open_tracking": { - "enable": True, - "substitution_tag": "%opentrack" - }, - "subscription_tracking": { - "enable": True, - "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.", - "substitution_tag": "<%click here%>", - "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>." } - } } response = sg.client.mail.send.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/mailboxproviders/mailboxproviders.py b/examples/mailboxproviders/mailboxproviders.py index 1b75ecac5..4fbf470e2 100644 --- a/examples/mailboxproviders/mailboxproviders.py +++ b/examples/mailboxproviders/mailboxproviders.py @@ -1,17 +1,20 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve email statistics by mailbox provider. # # GET /mailbox_providers/stats # -params = {'end_date': '2016-04-01', 'mailbox_providers': 'test_string', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'} +params = {'end_date': '2016-04-01', + 'mailbox_providers': 'test_string', + 'aggregated_by': 'day', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01'} response = sg.client.mailbox_providers.stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/mailsettings/mailsettings.py b/examples/mailsettings/mailsettings.py index 18c57b960..a4d46e399 100644 --- a/examples/mailsettings/mailsettings.py +++ b/examples/mailsettings/mailsettings.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve all mail settings # @@ -20,11 +19,11 @@ # PATCH /mail_settings/address_whitelist # data = { - "enabled": True, - "list": [ - "email1@example.com", - "example.com" - ] + "enabled": True, + "list": [ + "email1@example.com", + "example.com" + ] } response = sg.client.mail_settings.address_whitelist.patch(request_body=data) print(response.status_code) @@ -45,8 +44,8 @@ # PATCH /mail_settings/bcc # data = { - "email": "email@example.com", - "enabled": False + "email": "email@example.com", + "enabled": False } response = sg.client.mail_settings.bcc.patch(request_body=data) print(response.status_code) @@ -67,9 +66,9 @@ # PATCH /mail_settings/bounce_purge # data = { - "enabled": True, - "hard_bounces": 5, - "soft_bounces": 5 + "enabled": True, + "hard_bounces": 5, + "soft_bounces": 5 } response = sg.client.mail_settings.bounce_purge.patch(request_body=data) print(response.status_code) @@ -90,9 +89,9 @@ # PATCH /mail_settings/footer # data = { - "enabled": True, - "html_content": "...", - "plain_content": "..." + "enabled": True, + "html_content": "...", + "plain_content": "..." } response = sg.client.mail_settings.footer.patch(request_body=data) print(response.status_code) @@ -113,8 +112,8 @@ # PATCH /mail_settings/forward_bounce # data = { - "email": "example@example.com", - "enabled": True + "email": "example@example.com", + "enabled": True } response = sg.client.mail_settings.forward_bounce.patch(request_body=data) print(response.status_code) @@ -135,8 +134,8 @@ # PATCH /mail_settings/forward_spam # data = { - "email": "", - "enabled": False + "email": "", + "enabled": False } response = sg.client.mail_settings.forward_spam.patch(request_body=data) print(response.status_code) @@ -157,7 +156,7 @@ # PATCH /mail_settings/plain_content # data = { - "enabled": False + "enabled": False } response = sg.client.mail_settings.plain_content.patch(request_body=data) print(response.status_code) @@ -178,9 +177,9 @@ # PATCH /mail_settings/spam_check # data = { - "enabled": True, - "max_score": 5, - "url": "url" + "enabled": True, + "max_score": 5, + "url": "url" } response = sg.client.mail_settings.spam_check.patch(request_body=data) print(response.status_code) @@ -201,8 +200,8 @@ # PATCH /mail_settings/template # data = { - "enabled": True, - "html_content": "<% body %>" + "enabled": True, + "html_content": "<% body %>" } response = sg.client.mail_settings.template.patch(request_body=data) print(response.status_code) @@ -217,4 +216,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/partnersettings/partnersettings.py b/examples/partnersettings/partnersettings.py index 37f77f4e6..d3675a6ba 100644 --- a/examples/partnersettings/partnersettings.py +++ b/examples/partnersettings/partnersettings.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Returns a list of all partner settings. # @@ -20,9 +19,9 @@ # PATCH /partner_settings/new_relic # data = { - "enable_subuser_statistics": True, - "enabled": True, - "license_key": "" + "enable_subuser_statistics": True, + "enabled": True, + "license_key": "" } response = sg.client.partner_settings.new_relic.patch(request_body=data) print(response.status_code) @@ -37,4 +36,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/scopes/scopes.py b/examples/scopes/scopes.py index 124f77d39..99519dc3e 100644 --- a/examples/scopes/scopes.py +++ b/examples/scopes/scopes.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve a list of scopes for which this user has access. # @@ -13,4 +12,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/whitelabel/whitelabel.py b/examples/senderauthentication/senderauthentication.py similarity index 67% rename from examples/whitelabel/whitelabel.py rename to examples/senderauthentication/senderauthentication.py index f529d3ed2..f842d9302 100644 --- a/examples/whitelabel/whitelabel.py +++ b/examples/senderauthentication/senderauthentication.py @@ -3,23 +3,23 @@ import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## -# Create a domain whitelabel. # +# Create a domain authentication. # # POST /whitelabel/domains # data = { - "automatic_security": False, - "custom_spf": True, - "default": True, - "domain": "example.com", - "ips": [ - "192.168.1.1", - "192.168.1.2" - ], - "subdomain": "news", - "username": "john@example.com" + "automatic_security": False, + "custom_spf": True, + "default": True, + "domain": "example.com", + "ips": [ + "192.168.1.1", + "192.168.1.2" + ], + "subdomain": "news", + "username": "john@example.com" } response = sg.client.whitelabel.domains.post(request_body=data) print(response.status_code) @@ -27,17 +27,18 @@ print(response.headers) ################################################## -# List all domain whitelabels. # +# List all domain authentications. # # GET /whitelabel/domains # -params = {'username': 'test_string', 'domain': 'test_string', 'exclude_subusers': 'true', 'limit': 1, 'offset': 1} +params = {'username': 'test_string', 'domain': 'test_string', + 'exclude_subusers': 'true', 'limit': 1, 'offset': 1} response = sg.client.whitelabel.domains.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Get the default domain whitelabel. # +# Get the default domain authentication. # # GET /whitelabel/domains/default # response = sg.client.whitelabel.domains.default.get() @@ -46,7 +47,7 @@ print(response.headers) ################################################## -# List the domain whitelabel associated with the given user. # +# List the domain authentication associated with the given user. # # GET /whitelabel/domains/subuser # response = sg.client.whitelabel.domains.subuser.get() @@ -55,7 +56,7 @@ print(response.headers) ################################################## -# Disassociate a domain whitelabel from a given user. # +# Disassociate a domain authentication from a given user. # # DELETE /whitelabel/domains/subuser # response = sg.client.whitelabel.domains.subuser.delete() @@ -64,12 +65,12 @@ print(response.headers) ################################################## -# Update a domain whitelabel. # +# Update a domain authentication. # # PATCH /whitelabel/domains/{domain_id} # data = { - "custom_spf": True, - "default": False + "custom_spf": True, + "default": False } domain_id = "test_url_param" response = sg.client.whitelabel.domains._(domain_id).patch(request_body=data) @@ -78,7 +79,7 @@ print(response.headers) ################################################## -# Retrieve a domain whitelabel. # +# Retrieve a domain authentication. # # GET /whitelabel/domains/{domain_id} # domain_id = "test_url_param" @@ -88,7 +89,7 @@ print(response.headers) ################################################## -# Delete a domain whitelabel. # +# Delete a domain authentication. # # DELETE /whitelabel/domains/{domain_id} # domain_id = "test_url_param" @@ -98,60 +99,61 @@ print(response.headers) ################################################## -# Associate a domain whitelabel with a given user. # +# Associate a domain authentication with a given user. # # POST /whitelabel/domains/{domain_id}/subuser # data = { - "username": "jane@example.com" + "username": "jane@example.com" } domain_id = "test_url_param" -response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body=data) +response = sg.client.whitelabel.domains._( + domain_id).subuser.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Add an IP to a domain whitelabel. # +# Add an IP to a domain authentication. # # POST /whitelabel/domains/{id}/ips # data = { - "ip": "192.168.0.1" + "ip": "192.168.0.1" } -id = "test_url_param" -response = sg.client.whitelabel.domains._(id).ips.post(request_body=data) +id_ = "test_url_param" +response = sg.client.whitelabel.domains._(id_).ips.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Remove an IP from a domain whitelabel. # +# Remove an IP from a domain authentication. # # DELETE /whitelabel/domains/{id}/ips/{ip} # -id = "test_url_param" +id_ = "test_url_param" ip = "test_url_param" -response = sg.client.whitelabel.domains._(id).ips._(ip).delete() +response = sg.client.whitelabel.domains._(id_).ips._(ip).delete() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Validate a domain whitelabel. # +# Validate a domain authentication. # # POST /whitelabel/domains/{id}/validate # -id = "test_url_param" -response = sg.client.whitelabel.domains._(id).validate.post() +id_ = "test_url_param" +response = sg.client.whitelabel.domains._(id_).validate.post() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Create an IP whitelabel # +# Create a reverse DNS record # # POST /whitelabel/ips # data = { - "domain": "example.com", - "ip": "192.168.1.1", - "subdomain": "email" + "domain": "example.com", + "ip": "192.168.1.1", + "subdomain": "email" } response = sg.client.whitelabel.ips.post(request_body=data) print(response.status_code) @@ -159,7 +161,7 @@ print(response.headers) ################################################## -# Retrieve all IP whitelabels # +# Create a reverse DNS record # # GET /whitelabel/ips # params = {'ip': 'test_string', 'limit': 1, 'offset': 1} @@ -169,52 +171,53 @@ print(response.headers) ################################################## -# Retrieve an IP whitelabel # +# Retrieve a reverse DNS record # # GET /whitelabel/ips/{id} # -id = "test_url_param" -response = sg.client.whitelabel.ips._(id).get() +id_ = "test_url_param" +response = sg.client.whitelabel.ips._(id_).get() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Delete an IP whitelabel # +# Delete a reverse DNS record # # DELETE /whitelabel/ips/{id} # -id = "test_url_param" -response = sg.client.whitelabel.ips._(id).delete() +id_ = "test_url_param" +response = sg.client.whitelabel.ips._(id_).delete() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Validate an IP whitelabel # +# Validate a reverse DNS record # # POST /whitelabel/ips/{id}/validate # -id = "test_url_param" -response = sg.client.whitelabel.ips._(id).validate.post() +id_ = "test_url_param" +response = sg.client.whitelabel.ips._(id_).validate.post() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Create a Link Whitelabel # +# Create a Link Branding # # POST /whitelabel/links # data = { - "default": True, - "domain": "example.com", - "subdomain": "mail" + "default": True, + "domain": "example.com", + "subdomain": "mail" } params = {'limit': 1, 'offset': 1} -response = sg.client.whitelabel.links.post(request_body=data, query_params=params) +response = sg.client.whitelabel.links.post( + request_body=data, query_params=params) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Retrieve all link whitelabels # +# Retrieve all link brandings # # GET /whitelabel/links # params = {'limit': 1} @@ -224,7 +227,7 @@ print(response.headers) ################################################## -# Retrieve a Default Link Whitelabel # +# Retrieve a Default Link Branding # # GET /whitelabel/links/default # params = {'domain': 'test_string'} @@ -234,7 +237,7 @@ print(response.headers) ################################################## -# Retrieve Associated Link Whitelabel # +# Retrieve Associated Link Branding # # GET /whitelabel/links/subuser # params = {'username': 'test_string'} @@ -244,7 +247,7 @@ print(response.headers) ################################################## -# Disassociate a Link Whitelabel # +# Disassociate a Link Branding # # DELETE /whitelabel/links/subuser # params = {'username': 'test_string'} @@ -254,58 +257,58 @@ print(response.headers) ################################################## -# Update a Link Whitelabel # +# Update a Link Branding # # PATCH /whitelabel/links/{id} # data = { - "default": True + "default": True } -id = "test_url_param" -response = sg.client.whitelabel.links._(id).patch(request_body=data) +id_ = "test_url_param" +response = sg.client.whitelabel.links._(id_).patch(request_body=data) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Retrieve a Link Whitelabel # +# Retrieve a Link Branding # # GET /whitelabel/links/{id} # -id = "test_url_param" -response = sg.client.whitelabel.links._(id).get() +id_ = "test_url_param" +response = sg.client.whitelabel.links._(id_).get() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Delete a Link Whitelabel # +# Delete a Link Branding # # DELETE /whitelabel/links/{id} # -id = "test_url_param" -response = sg.client.whitelabel.links._(id).delete() +id_ = "test_url_param" +response = sg.client.whitelabel.links._(id_).delete() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Validate a Link Whitelabel # +# Validate a Link Branding # # POST /whitelabel/links/{id}/validate # -id = "test_url_param" -response = sg.client.whitelabel.links._(id).validate.post() +id_ = "test_url_param" +response = sg.client.whitelabel.links._(id_).validate.post() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Associate a Link Whitelabel # +# Associate a Link Branding # # POST /whitelabel/links/{link_id}/subuser # data = { - "username": "jane@example.com" + "username": "jane@example.com" } link_id = "test_url_param" -response = sg.client.whitelabel.links._(link_id).subuser.post(request_body=data) +response = sg.client.whitelabel.links._( + link_id).subuser.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/senders/senders.py b/examples/senders/senders.py index f21459b71..55eb44631 100644 --- a/examples/senders/senders.py +++ b/examples/senders/senders.py @@ -1,30 +1,29 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Create a Sender Identity # # POST /senders # data = { - "address": "123 Elm St.", - "address_2": "Apt. 456", - "city": "Denver", - "country": "United States", - "from": { - "email": "from@example.com", - "name": "Example INC" - }, - "nickname": "My Sender ID", - "reply_to": { - "email": "replyto@example.com", - "name": "Example INC" - }, - "state": "Colorado", - "zip": "80202" + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" } response = sg.client.senders.post(request_body=data) print(response.status_code) @@ -45,21 +44,21 @@ # PATCH /senders/{sender_id} # data = { - "address": "123 Elm St.", - "address_2": "Apt. 456", - "city": "Denver", - "country": "United States", - "from": { - "email": "from@example.com", - "name": "Example INC" - }, - "nickname": "My Sender ID", - "reply_to": { - "email": "replyto@example.com", - "name": "Example INC" - }, - "state": "Colorado", - "zip": "80202" + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" } sender_id = "test_url_param" response = sg.client.senders._(sender_id).patch(request_body=data) @@ -96,4 +95,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/stats/stats.py b/examples/stats/stats.py index a7bf3362e..cde422447 100644 --- a/examples/stats/stats.py +++ b/examples/stats/stats.py @@ -1,17 +1,16 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve global email statistics # # GET /stats # -params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1} +params = {'aggregated_by': 'day', 'limit': 1, + 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1} response = sg.client.stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/subusers/subusers.py b/examples/subusers/subusers.py index 6aa91e535..0f5ba6fe0 100644 --- a/examples/subusers/subusers.py +++ b/examples/subusers/subusers.py @@ -1,22 +1,21 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Create Subuser # # POST /subusers # data = { - "email": "John@example.com", - "ips": [ - "1.1.1.1", - "2.2.2.2" - ], - "password": "johns_password", - "username": "John@example.com" + "email": "John@example.com", + "ips": [ + "1.1.1.1", + "2.2.2.2" + ], + "password": "johns_password", + "username": "John@example.com" } response = sg.client.subusers.post(request_body=data) print(response.status_code) @@ -47,7 +46,12 @@ # Retrieve email statistics for your subusers. # # GET /subusers/stats # -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'subusers': 'test_string'} +params = {'end_date': '2016-04-01', + 'aggregated_by': 'day', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01', + 'subusers': 'test_string'} response = sg.client.subusers.stats.get(query_params=params) print(response.status_code) print(response.body) @@ -57,7 +61,12 @@ # Retrieve monthly stats for all subusers # # GET /subusers/stats/monthly # -params = {'subuser': 'test_string', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'date': 'test_string', 'sort_by_direction': 'asc'} +params = {'subuser': 'test_string', + 'limit': 1, + 'sort_by_metric': 'test_string', + 'offset': 1, + 'date': 'test_string', + 'sort_by_direction': 'asc'} response = sg.client.subusers.stats.monthly.get(query_params=params) print(response.status_code) print(response.body) @@ -67,7 +76,13 @@ # Retrieve the totals for each email statistic metric for all subusers. # # GET /subusers/stats/sums # -params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'} +params = {'end_date': '2016-04-01', + 'aggregated_by': 'day', + 'limit': 1, + 'sort_by_metric': 'test_string', + 'offset': 1, + 'start_date': '2016-01-01', + 'sort_by_direction': 'asc'} response = sg.client.subusers.stats.sums.get(query_params=params) print(response.status_code) print(response.body) @@ -78,7 +93,7 @@ # PATCH /subusers/{subuser_name} # data = { - "disabled": False + "disabled": False } subuser_name = "test_url_param" response = sg.client.subusers._(subuser_name).patch(request_body=data) @@ -101,7 +116,7 @@ # PUT /subusers/{subuser_name}/ips # data = [ - "127.0.0.1" + "127.0.0.1" ] subuser_name = "test_url_param" response = sg.client.subusers._(subuser_name).ips.put(request_body=data) @@ -114,8 +129,8 @@ # PUT /subusers/{subuser_name}/monitor # data = { - "email": "example@example.com", - "frequency": 500 + "email": "example@example.com", + "frequency": 500 } subuser_name = "test_url_param" response = sg.client.subusers._(subuser_name).monitor.put(request_body=data) @@ -128,8 +143,8 @@ # POST /subusers/{subuser_name}/monitor # data = { - "email": "example@example.com", - "frequency": 50000 + "email": "example@example.com", + "frequency": 50000 } subuser_name = "test_url_param" response = sg.client.subusers._(subuser_name).monitor.post(request_body=data) @@ -161,10 +176,14 @@ # Retrieve the monthly email statistics for a single subuser # # GET /subusers/{subuser_name}/stats/monthly # -params = {'date': 'test_string', 'sort_by_direction': 'asc', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1} +params = {'date': 'test_string', + 'sort_by_direction': 'asc', + 'limit': 1, + 'sort_by_metric': 'test_string', + 'offset': 1} subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params=params) +response = sg.client.subusers._( + subuser_name).stats.monthly.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/suppression/suppression.py b/examples/suppression/suppression.py index abdaef76d..430f76f35 100644 --- a/examples/suppression/suppression.py +++ b/examples/suppression/suppression.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve all blocks # @@ -20,11 +19,11 @@ # DELETE /suppression/blocks # data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] } response = sg.client.suppression.blocks.delete(request_body=data) print(response.status_code) @@ -66,11 +65,11 @@ # DELETE /suppression/bounces # data = { - "delete_all": True, - "emails": [ - "example@example.com", - "example2@example.com" - ] + "delete_all": True, + "emails": [ + "example@example.com", + "example2@example.com" + ] } response = sg.client.suppression.bounces.delete(request_body=data) print(response.status_code) @@ -113,11 +112,11 @@ # DELETE /suppression/invalid_emails # data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] } response = sg.client.suppression.invalid_emails.delete(request_body=data) print(response.status_code) @@ -179,11 +178,11 @@ # DELETE /suppression/spam_reports # data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] } response = sg.client.suppression.spam_reports.delete(request_body=data) print(response.status_code) @@ -199,4 +198,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/templates/templates.py b/examples/templates/templates.py index 9d3d5dd4b..9b5210191 100644 --- a/examples/templates/templates.py +++ b/examples/templates/templates.py @@ -1,16 +1,15 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Create a transactional template. # # POST /templates # data = { - "name": "example_name" + "name": "example_name" } response = sg.client.templates.post(request_body=data) print(response.status_code) @@ -31,7 +30,7 @@ # PATCH /templates/{template_id} # data = { - "name": "new_example_name" + "name": "new_example_name" } template_id = "test_url_param" response = sg.client.templates._(template_id).patch(request_body=data) @@ -64,12 +63,12 @@ # POST /templates/{template_id}/versions # data = { - "active": 1, - "html_content": "<%body%>", - "name": "example_version_name", - "plain_content": "<%body%>", - "subject": "<%subject%>", - "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" + "active": 1, + "html_content": "<%body%>", + "name": "example_version_name", + "plain_content": "<%body%>", + "subject": "<%subject%>", + "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" } template_id = "test_url_param" response = sg.client.templates._(template_id).versions.post(request_body=data) @@ -82,15 +81,16 @@ # PATCH /templates/{template_id}/versions/{version_id} # data = { - "active": 1, - "html_content": "<%body%>", - "name": "updated_example_name", - "plain_content": "<%body%>", - "subject": "<%subject%>" + "active": 1, + "html_content": "<%body%>", + "name": "updated_example_name", + "plain_content": "<%body%>", + "subject": "<%subject%>" } template_id = "test_url_param" version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).patch(request_body=data) +response = sg.client.templates._(template_id).versions._( + version_id).patch(request_body=data) print(response.status_code) print(response.body) print(response.headers) @@ -123,8 +123,8 @@ template_id = "test_url_param" version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).activate.post() +response = sg.client.templates._( + template_id).versions._(version_id).activate.post() print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/trackingsettings/trackingsettings.py b/examples/trackingsettings/trackingsettings.py index 80dbe243a..b3c49f8b2 100644 --- a/examples/trackingsettings/trackingsettings.py +++ b/examples/trackingsettings/trackingsettings.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Retrieve Tracking Settings # @@ -20,7 +19,7 @@ # PATCH /tracking_settings/click # data = { - "enabled": True + "enabled": True } response = sg.client.tracking_settings.click.patch(request_body=data) print(response.status_code) @@ -41,14 +40,15 @@ # PATCH /tracking_settings/google_analytics # data = { - "enabled": True, - "utm_campaign": "website", - "utm_content": "", - "utm_medium": "email", - "utm_source": "sendgrid.com", - "utm_term": "" + "enabled": True, + "utm_campaign": "website", + "utm_content": "", + "utm_medium": "email", + "utm_source": "sendgrid.com", + "utm_term": "" } -response = sg.client.tracking_settings.google_analytics.patch(request_body=data) +response = sg.client.tracking_settings.google_analytics.patch( + request_body=data) print(response.status_code) print(response.body) print(response.headers) @@ -67,7 +67,7 @@ # PATCH /tracking_settings/open # data = { - "enabled": True + "enabled": True } response = sg.client.tracking_settings.open.patch(request_body=data) print(response.status_code) @@ -88,12 +88,12 @@ # PATCH /tracking_settings/subscription # data = { - "enabled": True, - "html_content": "html content", - "landing": "landing page html", - "plain_content": "text content", - "replace": "replacement tag", - "url": "url" + "enabled": True, + "html_content": "html content", + "landing": "landing page html", + "plain_content": "text content", + "replace": "replacement tag", + "url": "url" } response = sg.client.tracking_settings.subscription.patch(request_body=data) print(response.status_code) @@ -108,4 +108,3 @@ print(response.status_code) print(response.body) print(response.headers) - diff --git a/examples/user/user.py b/examples/user/user.py index e71a8d11e..5160f9ff8 100644 --- a/examples/user/user.py +++ b/examples/user/user.py @@ -1,9 +1,8 @@ import sendgrid -import json import os -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) ################################################## # Get a user's account information. # @@ -28,7 +27,7 @@ # PUT /user/email # data = { - "email": "example@example.com" + "email": "example@example.com" } response = sg.client.user.email.put(request_body=data) print(response.status_code) @@ -49,8 +48,8 @@ # PUT /user/password # data = { - "new_password": "new_password", - "old_password": "old_password" + "new_password": "new_password", + "old_password": "old_password" } response = sg.client.user.password.put(request_body=data) print(response.status_code) @@ -62,9 +61,9 @@ # PATCH /user/profile # data = { - "city": "Orange", - "first_name": "Example", - "last_name": "User" + "city": "Orange", + "first_name": "Example", + "last_name": "User" } response = sg.client.user.profile.patch(request_body=data) print(response.status_code) @@ -85,8 +84,8 @@ # POST /user/scheduled_sends # data = { - "batch_id": "YOUR_BATCH_ID", - "status": "pause" + "batch_id": "YOUR_BATCH_ID", + "status": "pause" } response = sg.client.user.scheduled_sends.post(request_body=data) print(response.status_code) @@ -107,7 +106,7 @@ # PATCH /user/scheduled_sends/{batch_id} # data = { - "status": "pause" + "status": "pause" } batch_id = "test_url_param" response = sg.client.user.scheduled_sends._(batch_id).patch(request_body=data) @@ -140,8 +139,8 @@ # PATCH /user/settings/enforced_tls # data = { - "require_tls": True, - "require_valid_cert": False + "require_tls": True, + "require_valid_cert": False } response = sg.client.user.settings.enforced_tls.patch(request_body=data) print(response.status_code) @@ -162,7 +161,7 @@ # PUT /user/username # data = { - "username": "test_username" + "username": "test_username" } response = sg.client.user.username.put(request_body=data) print(response.status_code) @@ -183,19 +182,19 @@ # PATCH /user/webhooks/event/settings # data = { - "bounce": True, - "click": True, - "deferred": True, - "delivered": True, - "dropped": True, - "enabled": True, - "group_resubscribe": True, - "group_unsubscribe": True, - "open": True, - "processed": True, - "spam_report": True, - "unsubscribe": True, - "url": "url" + "bounce": True, + "click": True, + "deferred": True, + "delivered": True, + "dropped": True, + "enabled": True, + "group_resubscribe": True, + "group_unsubscribe": True, + "open": True, + "processed": True, + "spam_report": True, + "unsubscribe": True, + "url": "url" } response = sg.client.user.webhooks.event.settings.patch(request_body=data) print(response.status_code) @@ -216,7 +215,7 @@ # POST /user/webhooks/event/test # data = { - "url": "url" + "url": "url" } response = sg.client.user.webhooks.event.test.post(request_body=data) print(response.status_code) @@ -228,10 +227,10 @@ # POST /user/webhooks/parse/settings # data = { - "hostname": "myhostname.com", - "send_raw": False, - "spam_check": True, - "url": "http://email.myhosthame.com" + "hostname": "myhostname.com", + "send_raw": False, + "spam_check": True, + "url": "http://email.myhosthame.com" } response = sg.client.user.webhooks.parse.settings.post(request_body=data) print(response.status_code) @@ -252,12 +251,13 @@ # PATCH /user/webhooks/parse/settings/{hostname} # data = { - "send_raw": True, - "spam_check": False, - "url": "http://newdomain.com/parse" + "send_raw": True, + "spam_check": False, + "url": "http://newdomain.com/parse" } hostname = "test_url_param" -response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body=data) +response = sg.client.user.webhooks.parse.settings._( + hostname).patch(request_body=data) print(response.status_code) print(response.body) print(response.headers) @@ -286,9 +286,12 @@ # Retrieves Inbound Parse Webhook statistics. # # GET /user/webhooks/parse/stats # -params = {'aggregated_by': 'day', 'limit': 'test_string', 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 'test_string'} +params = {'aggregated_by': 'day', + 'limit': 'test_string', + 'start_date': '2016-01-01', + 'end_date': '2016-04-01', + 'offset': 'test_string'} response = sg.client.user.webhooks.parse.stats.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) - diff --git a/live_test.py b/live_test.py new file mode 100644 index 000000000..d666140fb --- /dev/null +++ b/live_test.py @@ -0,0 +1,357 @@ +## Send a Single Email to a Single Recipient +import os +import json +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException + +message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'), + to_emails=To('ethomas@twilio.com', 'Elmer Thomas'), + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + +try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message=message) + print(response.status_code) + print(response.body) + print(response.headers) +except SendGridException as e: + print(e.message) + +# Send a Single Email to Multiple Recipients +import os +import json +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException + +to_emails = [ + To('ethomas@twilio.com', 'Elmer SendGrid'), + To('elmer.thomas@gmail.com', 'Elmer Thomas') +] +message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'), + to_emails=to_emails, + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + +try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message=message) + print(response.status_code) + print(response.body) + print(response.headers) +except SendGridException as e: + print(e.message) + +# Send Multiple Emails to Multiple Recipients + +import os +import json +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException, Substitution +import time +import datetime + +to_emails = [ + To(email='ethomas@twilio.com', + name='Elmer Twilio', + substitutions={ + Substitution('-name-', 'Elmer Twilio'), + Substitution('-github-', 'http://github.com/ethomas'), + }, + subject=Subject('Override Global Subject')), + To(email='elmer.thomas@gmail.com', + name='Elmer Thomas', + substitutions={ + Substitution('-name-', 'Elmer Thomas'), + Substitution('-github-', 'http://github.com/thinkingserious'), + }) +] +ts = time.time() +global_substitutions = Substitution('-time-', datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')) +message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'), + to_emails=to_emails, + subject=Subject('Hi -name-'), + plain_text_content=PlainTextContent('Hello -name-, your github is -github-, email sent at -time-'), + html_content=HtmlContent('Hello -name-, your github is here email sent at -time-'), + global_substitutions=global_substitutions, + is_multiple=True) + +try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message=message) + print(response.status_code) + print(response.body) + print(response.headers) +except SendGridException as e: + print(e.message) + +# Kitchen Sink - an example with all settings used + +import os +import json +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import ( + Mail, From, To, Cc, Bcc, Subject, PlainTextContent, + HtmlContent, SendGridException, Substitution, + Header, CustomArg, SendAt, Content, MimeType, Attachment, + FileName, FileContent, FileType, Disposition, ContentId, + TemplateId, Section, ReplyTo, Category, BatchId, Asm, + GroupId, GroupsToDisplay, IpPoolName, MailSettings, + BccSettings, BccSettingsEmail, BypassListManagement, + FooterSettings, FooterText, FooterHtml, SandBoxMode, + SpamCheck, SpamThreshold, SpamUrl, TrackingSettings, + ClickTracking, SubscriptionTracking, SubscriptionText, + SubscriptionHtml, SubscriptionSubstitutionTag, + OpenTracking, OpenTrackingSubstitutionTag, Ganalytics, + UtmSource, UtmMedium, UtmTerm, UtmContent, UtmCampaign) +import time +import datetime + +message = Mail() + +# Define Personalizations + +message.to = To('elmer+test1@sendgrid.com', 'Example User1', p=0) +message.to = [ + To('elmer+test2@sendgrid.com', 'Example User2', p=0), + To('elmer+test3@sendgrid.com', 'Example User3', p=0) +] + +message.cc = Cc('test4@example.com', 'Example User4', p=0) +message.cc = [ + Cc('test5@example.com', 'Example User5', p=0), + Cc('test6@example.com', 'Example User6', p=0) +] + +message.bcc = Bcc('test7@example.com', 'Example User7', p=0) +message.bcc = [ + Bcc('test8@example.com', 'Example User8', p=0), + Bcc('test9@example.com', 'Example User9', p=0) +] + +message.subject = Subject('Sending with SendGrid is Fun 0', p=0) + +message.header = Header('X-Test1', 'Test1', p=0) +message.header = Header('X-Test2', 'Test2', p=0) +message.header = [ + Header('X-Test3', 'Test3', p=0), + Header('X-Test4', 'Test4', p=0) +] + +message.substitution = Substitution('%name1%', 'Example Name 1', p=0) +message.substitution = Substitution('%city1%', 'Example City 1', p=0) +message.substitution = [ + Substitution('%name2%', 'Example Name 2', p=0), + Substitution('%city2%', 'Example City 2', p=0) +] + +message.custom_arg = CustomArg('marketing1', 'true', p=0) +message.custom_arg = CustomArg('transactional1', 'false', p=0) +message.custom_arg = [ + CustomArg('marketing2', 'false', p=0), + CustomArg('transactional2', 'true', p=0) +] + +message.send_at = SendAt(1461775051, p=0) + +message.to = To('test10@example.com', 'Example User10', p=1) +message.to = [ + To('test11@example.com', 'Example User11', p=1), + To('test12@example.com', 'Example User12', p=1) +] + +message.cc = Cc('test13@example.com', 'Example User13', p=1) +message.cc = [ + Cc('test14@example.com', 'Example User14', p=1), + Cc('test15@example.com', 'Example User15', p=1) +] + +message.bcc = Bcc('test16@example.com', 'Example User16', p=1) +message.bcc = [ + Bcc('test17@example.com', 'Example User17', p=1), + Bcc('test18@example.com', 'Example User18', p=1) +] + +message.header = Header('X-Test5', 'Test5', p=1) +message.header = Header('X-Test6', 'Test6', p=1) +message.header = [ + Header('X-Test7', 'Test7', p=1), + Header('X-Test8', 'Test8', p=1) +] + +message.substitution = Substitution('%name3%', 'Example Name 3', p=1) +message.substitution = Substitution('%city3%', 'Example City 3', p=1) +message.substitution = [ + Substitution('%name4%', 'Example Name 4', p=1), + Substitution('%city4%', 'Example City 4', p=1) +] + +message.custom_arg = CustomArg('marketing3', 'true', p=1) +message.custom_arg = CustomArg('transactional3', 'false', p=1) +message.custom_arg = [ + CustomArg('marketing4', 'false', p=1), + CustomArg('transactional4', 'true', p=1) +] + +message.send_at = SendAt(1461775052, p=1) + +message.subject = Subject('Sending with SendGrid is Fun 1', p=1) + +# The values below this comment are global to entire message + +message.from_email = From('help@twilio.com', 'Twilio SendGrid') + +message.reply_to = ReplyTo('help_reply@twilio.com', 'Twilio SendGrid Reply') + +message.subject = Subject('Sending with SendGrid is Fun 2') + +message.content = Content(MimeType.text, 'and easy to do anywhere, even with Python') +message.content = Content(MimeType.html, 'and easy to do anywhere, even with Python') +message.content = [ + Content('text/calendar', 'Party Time!!'), + Content('text/custom', 'Party Time 2!!') +] + +message.attachment = Attachment(FileContent('base64 encoded content 1'), + FileType('application/pdf'), + FileName('balance_001.pdf'), + Disposition('attachment'), + ContentId('Content ID 1')) +message.attachment = [ + Attachment(FileContent('base64 encoded content 2'), + FileType('image/png'), + FileName('banner.png'), + Disposition('inline'), + ContentId('Content ID 2')), + Attachment(FileContent('base64 encoded content 3'), + FileType('image/png'), + FileName('banner2.png'), + Disposition('inline'), + ContentId('Content ID 3')) +] + +message.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932') + +message.section = Section('%section1%', 'Substitution for Section 1 Tag') +message.section = [ + Section('%section2%', 'Substitution for Section 2 Tag'), + Section('%section3%', 'Substitution for Section 3 Tag') +] + +message.header = Header('X-Test9', 'Test9') +message.header = Header('X-Test10', 'Test10') +message.header = [ + Header('X-Test11', 'Test11'), + Header('X-Test12', 'Test12') +] + +message.category = Category('Category 1') +message.category = Category('Category 2') +message.category = [ + Category('Category 1'), + Category('Category 2') +] + +message.custom_arg = CustomArg('marketing5', 'false') +message.custom_arg = CustomArg('transactional5', 'true') +message.custom_arg = [ + CustomArg('marketing6', 'true'), + CustomArg('transactional6', 'false') +] + +message.send_at = SendAt(1461775053) + +message.batch_id = BatchId("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi") + +message.asm = Asm(GroupId(1), GroupsToDisplay([1,2,3,4])) + +message.ip_pool_name = IpPoolName("IP Pool Name") + +mail_settings = MailSettings() +mail_settings.bcc_settings = BccSettings(False, BccSettingsEmail("bcc@twilio.com")) +mail_settings.bypass_list_management = BypassListManagement(False) +mail_settings.footer_settings = FooterSettings(True, FooterText("w00t"), FooterHtml("