Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create README.md #683

Merged
merged 10 commits into from
Oct 30, 2018
37 changes: 37 additions & 0 deletions examples/helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## 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,
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved
building attachments, configuring settings, building personalizations,etc are made easy using helpers. All you need is a file with
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved
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.
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved

### 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.
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved

```
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.
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved

```
mail = Mail(from_email, subject, to_email, 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.
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved
for more information on parameters and usage, see [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py)
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved

### Creating Personalizations

To create personalizations, you need a dictionary to store all your email components. see example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L47)
tulikavijay marked this conversation as resolved.
Show resolved Hide resolved
After creating a dictionary, you can go ahead and create a `Personalization` object.
```
mock_personalization = Personalization()
for to_addr in personalization['to_list']:
mock_personalization.add_to(to_addr)
```