Skip to content

Commit

Permalink
Merge pull request sendgrid#190 from GustavoCaso/update-mail-helper-v…
Browse files Browse the repository at this point in the history
…3-with-feedback

Update mail helper v3 with feedback
  • Loading branch information
thinkingserious authored Oct 14, 2017
2 parents ae8f603 + de242d4 commit 9d0e01d
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions mail_helper_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ to = SendGrid::Email.new('[email protected]', 'Example User')
subject = 'Sending with SendGrid is Fun'
plain_text_content = 'and easy to do anywhere, even with Ruby'
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
msg = SendGrid::Mail.create_single_email(from, to, subject, plain_text_content, html_content)
msg = SendGrid::Mail.create(from: from,
tos: to,
subject: subject,
plain_text_content: plain_text_content,
html_content: html_content,
substitutions: {})

client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

begin
response = client.send_email(msg)
Expand All @@ -38,21 +43,22 @@ The following code assumes you are storing the API key in an [environment variab
require 'sendgrid-ruby'

from = SendGrid::Email.new('[email protected]', 'Example User')
tos = [
tos = [
SendGrid::Email.new('[email protected]', 'Example User1'),
SendGrid::Email.new('[email protected]', 'Example User2'),
SendGrid::Email.new('[email protected]', 'Example User3')
];
subject = 'Sending with SendGrid is Fun'
plain_text_content = 'and easy to do anywhere, even with Ruby'
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
msg = SendGrid::Mail.create_single_email_to_multiple_recipients(from,
tos,
subject,
plain_text_content,
html_content)
msg = SendGrid::Mail.create(from: from,
tos: tos,
subject: subject,
plain_text_content: plain_text_content,
html_content: html_content,
substitutions: {})

client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

begin
response = client.send_email(msg)
Expand All @@ -72,7 +78,7 @@ The following code assumes you are storing the API key in an [environment variab
require 'sendgrid-ruby'

from = SendGrid::Email.new('[email protected]', 'Example User')
tos = [
tos = [
SendGrid::Email.new('[email protected]', 'Example User1'),
SendGrid::Email.new('[email protected]', 'Example User2'),
SendGrid::Email.new('[email protected]', 'Example User3')
Expand All @@ -92,14 +98,14 @@ values = [
substitutions = {
'-name1-' => values
}
msg = SendGrid::Mail.create_multiple_emails_to_multiple_recipients(from,
tos,
subjects,
plain_text_content,
html_content,
substitutions)
msg = SendGrid::Mail.create(from: from,
tos: tos,
subject: subjects,
plain_text_content: plain_text_content,
html_content: html_content,
substitutions: substitutions)

client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

begin
response = client.send_email(msg)
Expand All @@ -116,33 +122,33 @@ puts response.headers
The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.

```ruby
client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

from = SendGrid::Email.new('[email protected]', 'Example User')
to = SendGrid::Email.new('[email protected]', 'Example User')
subject = 'Sending with SendGrid is Fun'
plain_text_content = 'and easy to do anywhere, even with Ruby'
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
msg = SendGrid::SendGridMessage.new(from, to, subject, plain_text_content, html_content)
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)

# For a detailed description of each of these settings, please see the [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html).

msg.add_to(SendGrid::Email.new('[email protected]', 'Example User1'))
to_emails = [
to_emails = [
SendGrid::Email.new('[email protected]', 'Example User2'),
SendGrid::Email.new('[email protected]', 'Example User3')
];
msg.add_tos(to_emails)

msg.add_cc(SendGrid::Email.new('[email protected]', 'Example User4'))
cc_emails = [
cc_emails = [
SendGrid::Email.new('[email protected]', 'Example User5'),
SendGrid::Email.new('[email protected]', 'Example User6')
];
msg.add_ccs(cc_emails)

msg.add_bcc(SendGrid::Email.new('[email protected]', 'Example User7'))
bcc_emails = [
bcc_emails = [
SendGrid::Email.new('[email protected]', 'Example User8'),
SendGrid::Email.new('[email protected]', 'Example User9')
];
Expand Down Expand Up @@ -179,21 +185,21 @@ msg.set_subject('this subject overrides the Global Subject on the default Person
# If you need to add more [Personalizations](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html), here is an example of adding another Personalization by passing in a personalization index.

msg.add_to(SendGrid::Email.new('[email protected]', 'Example User10'), 1)
to_emails = [
to_emails = [
SendGrid::Email.new('[email protected]', 'Example User11'),
SendGrid::Email.new('[email protected]', 'Example User12')
];
msg.add_tos(to_emails, 1)

msg.add_cc(SendGrid::Email.new('[email protected]', 'Example User13'), 1)
cc_emails = [
cc_emails = [
SendGrid::Email.new('[email protected]', 'Example User14'),
SendGrid::Email.new('[email protected]', 'Example User15')
];
msg.add_ccs(cc_emails, 1)

msg.add_bcc(SendGrid::Email.new('[email protected]', 'Example User16'), 1)
bcc_emails = [
bcc_emails = [
SendGrid::Email.new('[email protected]', 'Example User17'),
SendGrid::Email.new('[email protected]', 'Example User18')
];
Expand Down Expand Up @@ -292,16 +298,18 @@ puts response.headers
The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.

```ruby
client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

from = SendGrid::Email.new('[email protected]', 'Example User')
to = SendGrid::Email.new('[email protected]', 'Example User')
subject = 'Sending with SendGrid is Fun'
plain_text_content = 'and easy to do anywhere, even with Ruby'
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
msg = SendGrid::SendGridMessage.new(from, to, subject, plain_text_content, html_content)
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
bytes = File.read('/path/to/the/attachment.pdf')
encoded = Base64.encode64(bytes)
msg.add_attachment('balance_001.pdf',
'base64 encoded content',
encoded,
'application/pdf',
'attachment',
'Balance Sheet')
Expand Down Expand Up @@ -355,14 +363,14 @@ I hope you are having a great day in -city- :)
```

```ruby
client = SendGrid::ClientFactory.new(api_key: ENV['SENDGRID_API_KEY'])
client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])

from = SendGrid::Email.new('[email protected]', 'Example User')
to = SendGrid::Email.new('[email protected]', 'Example User')
subject = 'Sending with SendGrid is Fun'
plain_text_content = 'and easy to do anywhere, even with Ruby'
html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
msg = SendGrid::SendGridMessage.new(from, to, subject, plain_text_content, html_content)
msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)

substitutions = [
'-name-' => 'Example User',
Expand Down

0 comments on commit 9d0e01d

Please sign in to comment.