Skip to content
Closed
27 changes: 10 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
# Change Log
All notable changes to this project will be documented in this file.

## [5.6.0] - 2018-08-20 ##
### Added
- [PR #593](https://github.com/sendgrid/sendgrid-python/pull/593): Adds support for dynamic template data. Big thanks to [Slam](https://github.com/3lnc) for the PR! Also, big thanks to [Wojciech Bartosiak](https://github.com/wojtek-fliposports) for [PR #597](https://github.com/sendgrid/sendgrid-python/pull/597)!

## [5.5.0] - 2018-08-16 ##
### Added
- [PR #588](https://github.com/sendgrid/sendgrid-python/pull/588): Updates the Readme to include environment variable setup in windows. Big thanks to [Bhargav Chandaka](https://github.com/bchandaka) for the PR!
- [PR #599](https://github.com/sendgrid/sendgrid-python/pull/599): Updates the Readme to include additional API Key instruction. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR!
- [PR #600](https://github.com/sendgrid/sendgrid-python/pull/600): Add CodeTriage Badge. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR!
- [PR #601](https://github.com/sendgrid/sendgrid-python/pull/601): Readability improvements to CONTRIBUTING.md. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR!
- [PR #604](https://github.com/sendgrid/sendgrid-python/pull/604): Readability improvements to CONTRIBUTING.md. Big thanks to [agnesjang98](https://github.com/agnesjang98) for the PR!
## [6.0.0] - TBD

### Fixed
- [PR #595](https://github.com/sendgrid/sendgrid-python/pull/595): Change type of category in Mail.add_category from string to Category. Big thanks to [Phawin Khongkhasawan](https://github.com/lifez) for the PR!
- [PR #596](https://github.com/sendgrid/sendgrid-python/pull/596): Fix Docker build. Big thanks to [Phawin Khongkhasawan](https://github.com/lifez) for the PR!
- [PR #598](https://github.com/sendgrid/sendgrid-python/pull/598): Fix python3 print example in TROUBLESHOOTING.md. Big thanks to [Ryan Jarvis](https://github.com/Cabalist) for the PR!
- [PR #603](https://github.com/sendgrid/sendgrid-python/pull/603): Update TROUBLESHOOTING.md to link to correct use cases page. Big thanks to [James Purpura](https://github.com/jpurpura) for the PR!
- https://github.com/sendgrid/sendgrid-python/pull/486
- https://github.com/sendgrid/sendgrid-python/pull/488
- https://github.com/sendgrid/sendgrid-python/pull/493
- https://github.com/sendgrid/sendgrid-python/pull/496
- https://github.com/sendgrid/sendgrid-python/pull/509
- https://github.com/sendgrid/sendgrid-python/pull/510
- https://github.com/sendgrid/sendgrid-python/pull/512
- https://github.com/sendgrid/sendgrid-python/pull/524

## [5.4.1] - 2018-06-26 ##
### Fixed
- [PR #585](https://github.com/sendgrid/sendgrid-python/pull/585): Fix typo in `mail_example.py`. Big thanks to [Anurag Anand](https://github.com/theanuraganand) for the PR!
- [PR #583](https://github.com/sendgrid/sendgrid-python/pull/583): Fix `Personalization.substitutions` setter. Trying to set substitutions directly rather than with add_substitution was causing an infinite regress. Big thanks to [Richard Nias](https://github.com/richardnias) for the PR!
- [PR #583](https://github.com/sendgrid/sendgrid-python/pull/585): Fix `Personalization.substitutions` setter. Trying to set substitutions directly rather than with add_substitution was causing an infinite regress. Big thanks to [Richard Nias](https://github.com/richardnias) for the PR!

## [5.4.0] - 2018-06-07 ##
### Added
Expand Down
24 changes: 24 additions & 0 deletions live_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Send a Single Email to a Single Recipient
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException

message = Mail(from_email=From('dx@sendgrid.com', 'DX'),
to_emails=To('elmer.thomas@sendgrid.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('<strong>and easy to do anywhere, even with Python</strong>'))

try:
sendgrid_client = SendGridAPIClient(apikey=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)

# ToDo

## The Mail constructor should also support passing in tuples and strings
## The send function parameter should be better named, maybe email_message or simply message
19 changes: 10 additions & 9 deletions proposals/mail-helper-refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ This is the minimum code needed to send an email.

```python
import os
import sendgrid
from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException

msg = Mail(from_email=From('from@example.com', 'From Name'),
to_emails=To('to@example.com', 'To Name'),
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
html_content=HtmlContent('<strong>and easy to do anywhere, even with Python</strong>'))
message = Mail(from_email=From('from@example.com', 'From Name'),
to_emails=To('to@example.com', 'To Name'),
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
html_content=HtmlContent('<strong>and easy to do anywhere, even with Python</strong>'))

try:
response = sendgrid.send(msg, apikey=os.environ.get('SENDGRID_apikey'))
sendgrid_client = SendGridAPIClient(apikey=os.environ.get('SENDGRID_apikey'))
response = sendgrid_client.send(message=message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
except SendGridException as e:
print(e.read())
```

Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Flask==0.10.1
PyYAML==3.11
python-http-client==2.2.1
six==1.10.0
pytest==3.7.1
Flask==1.0.2
PyYAML==3.13
python-http-client==3.1.0
six==1.11.0
pytest==3.8.2
5 changes: 5 additions & 0 deletions sendgrid/helpers/mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
from .email import Email
from .exceptions import SendGridException, APIKeyIncludedException
from .footer_settings import FooterSettings
from .from_email import From
from .ganalytics import Ganalytics
from .header import Header
from .html_content import HtmlContent
from .mail_settings import MailSettings
from .mail import Mail
from .open_tracking import OpenTracking
from .personalization import Personalization
from .plain_text_content import PlainTextContent
from .sandbox_mode import SandBoxMode
from .section import Section
from .spam_check import SpamCheck
from .subject import Subject
from .subscription_tracking import SubscriptionTracking
from .substitution import Substitution
from .tracking_settings import TrackingSettings
from .to_email import To
from .validators import ValidateAPIKey
4 changes: 4 additions & 0 deletions sendgrid/helpers/mail/from_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .email import Email

class From(Email):
"""A from email address with an optional name."""
40 changes: 40 additions & 0 deletions sendgrid/helpers/mail/html_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from .content import Content
from .validators import ValidateAPIKey

class HtmlContent(Content):
"""HTML content to be included in your email."""

def __init__(self, value):
"""Create an HtmlContent with the specified MIME type and value.

:param value: The HTML content.
:type value: string, optional
"""
self._validator = ValidateAPIKey()
self.type = "text/html"
self.value = value

@property
def value(self):
"""The actual HTML content.

:rtype: string
"""
return self._value

@value.setter
def value(self, value):
self._validator.validate_message_dict(value)
self._value = value

def get(self):
"""
Get a JSON-ready representation of this HtmlContent.

:returns: This HtmlContent, ready for use in a request body.
:rtype: dict
"""
content = {}
content["type"] = "text/html"
content["value"] = self._value
return content
Loading