@@ -16,9 +16,14 @@ to = SendGrid::Email.new('test@example.com', 'Example User')
1616subject = ' Sending with SendGrid is Fun'
1717plain_text_content = ' and easy to do anywhere, even with Ruby'
1818html_content = ' <strong>and easy to do anywhere, even with Ruby</strong>'
19- msg = SendGrid ::Mail .create_single_email(from, to, subject, plain_text_content, html_content)
19+ msg = SendGrid ::Mail .create(from: from,
20+ tos: to,
21+ subject: subject,
22+ plain_text_content: plain_text_content,
23+ html_content: html_content,
24+ substitutions: {})
2025
21- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
26+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
2227
2328begin
2429 response = client.send_email(msg)
@@ -38,21 +43,22 @@ The following code assumes you are storing the API key in an [environment variab
3843require ' sendgrid-ruby'
3944
4045from = SendGrid ::Email .new (' test@example.com' , ' Example User' )
41- tos = [
46+ tos = [
4247 SendGrid ::Email .new (' test1@example.com' , ' Example User1' ),
4348 SendGrid ::Email .new (' test2@example.com' , ' Example User2' ),
4449 SendGrid ::Email .new (' test3@example.com' , ' Example User3' )
4550];
4651subject = ' Sending with SendGrid is Fun'
4752plain_text_content = ' and easy to do anywhere, even with Ruby'
4853html_content = ' <strong>and easy to do anywhere, even with Ruby</strong>'
49- msg = SendGrid ::Mail .create_single_email_to_multiple_recipients(from,
50- tos,
51- subject,
52- plain_text_content,
53- html_content)
54+ msg = SendGrid ::Mail .create(from: from,
55+ tos: tos,
56+ subject: subject,
57+ plain_text_content: plain_text_content,
58+ html_content: html_content,
59+ substitutions: {})
5460
55- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
61+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
5662
5763begin
5864 response = client.send_email(msg)
@@ -72,7 +78,7 @@ The following code assumes you are storing the API key in an [environment variab
7278require ' sendgrid-ruby'
7379
7480from = SendGrid ::Email .new (' test@example.com' , ' Example User' )
75- tos = [
81+ tos = [
7682 SendGrid ::Email .new (' test1@example.com' , ' Example User1' ),
7783 SendGrid ::Email .new (' test2@example.com' , ' Example User2' ),
7884 SendGrid ::Email .new (' test3@example.com' , ' Example User3' )
@@ -92,14 +98,14 @@ values = [
9298substitutions = {
9399 ' -name1-' => values
94100}
95- msg = SendGrid ::Mail .create_multiple_emails_to_multiple_recipients( from,
96- tos,
97- subjects,
98- plain_text_content,
99- html_content,
100- substitutions)
101+ msg = SendGrid ::Mail .create( from: from,
102+ tos: tos,
103+ subject: subjects,
104+ plain_text_content: plain_text_content,
105+ html_content: html_content,
106+ substitutions: substitutions)
101107
102- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
108+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
103109
104110begin
105111 response = client.send_email(msg)
@@ -116,33 +122,33 @@ puts response.headers
116122The 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.
117123
118124``` ruby
119- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
125+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
120126
121127from = SendGrid ::Email .new (' test@example.com' , ' Example User' )
122128to = SendGrid ::Email .new (' test@example.com' , ' Example User' )
123129subject = ' Sending with SendGrid is Fun'
124130plain_text_content = ' and easy to do anywhere, even with Ruby'
125131html_content = ' <strong>and easy to do anywhere, even with Ruby</strong>'
126- msg = SendGrid ::SendGridMessage .new (from, to, subject, plain_text_content, html_content)
132+ msg = SendGrid ::Message .new (from, to, subject, plain_text_content, html_content)
127133
128134# For a detailed description of each of these settings, please see the [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html).
129135
130136msg.add_to(SendGrid ::Email .new (' test1@example.com' , ' Example User1' ))
131- to_emails = [
137+ to_emails = [
132138 SendGrid ::Email .new (' test2@example.com' , ' Example User2' ),
133139 SendGrid ::Email .new (' test3@example.com' , ' Example User3' )
134140];
135141msg.add_tos(to_emails)
136142
137143msg.add_cc(SendGrid ::Email .new (' test4@example.com' , ' Example User4' ))
138- cc_emails = [
144+ cc_emails = [
139145 SendGrid ::Email .new (' test5@example.com' , ' Example User5' ),
140146 SendGrid ::Email .new (' test6@example.com' , ' Example User6' )
141147];
142148msg.add_ccs(cc_emails)
143149
144150msg.add_bcc(SendGrid ::Email .new (' test7@example.com' , ' Example User7' ))
145- bcc_emails = [
151+ bcc_emails = [
146152 SendGrid ::Email .new (' test8@example.com' , ' Example User8' ),
147153 SendGrid ::Email .new (' test9@example.com' , ' Example User9' )
148154];
@@ -179,21 +185,21 @@ msg.set_subject('this subject overrides the Global Subject on the default Person
179185# 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.
180186
181187msg.add_to(SendGrid ::Email .new (' test10@example.com' , ' Example User10' ), 1 )
182- to_emails = [
188+ to_emails = [
183189 SendGrid ::Email .new (' test11@example.com' , ' Example User11' ),
184190 SendGrid ::Email .new (' test12@example.com' , ' Example User12' )
185191];
186192msg.add_tos(to_emails, 1 )
187193
188194msg.add_cc(SendGrid ::Email .new (' test13@example.com' , ' Example User13' ), 1 )
189- cc_emails = [
195+ cc_emails = [
190196 SendGrid ::Email .new (' test14@example.com' , ' Example User14' ),
191197 SendGrid ::Email .new (' test15@example.com' , ' Example User15' )
192198];
193199msg.add_ccs(cc_emails, 1 )
194200
195201msg.add_bcc(SendGrid ::Email .new (' test16@example.com' , ' Example User16' ), 1 )
196- bcc_emails = [
202+ bcc_emails = [
197203 SendGrid ::Email .new (' test17@example.com' , ' Example User17' ),
198204 SendGrid ::Email .new (' test18@example.com' , ' Example User18' )
199205];
@@ -292,16 +298,18 @@ puts response.headers
292298The 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.
293299
294300``` ruby
295- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
301+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
296302
297303from = SendGrid ::Email .new (' test@example.com' , ' Example User' )
298304to = SendGrid ::Email .new (' test@example.com' , ' Example User' )
299305subject = ' Sending with SendGrid is Fun'
300306plain_text_content = ' and easy to do anywhere, even with Ruby'
301307html_content = ' <strong>and easy to do anywhere, even with Ruby</strong>'
302- msg = SendGrid ::SendGridMessage .new (from, to, subject, plain_text_content, html_content)
308+ msg = SendGrid ::Message .new (from, to, subject, plain_text_content, html_content)
309+ bytes = File .read(' /path/to/the/attachment.pdf' )
310+ encoded = Base64 .encode64(bytes)
303311msg.add_attachment(' balance_001.pdf' ,
304- ' base64 encoded content ' ,
312+ encoded,
305313 ' application/pdf' ,
306314 ' attachment' ,
307315 ' Balance Sheet' )
@@ -355,14 +363,14 @@ I hope you are having a great day in -city- :)
355363```
356364
357365``` ruby
358- client = SendGrid ::ClientFactory .new (api_key: ENV [' SENDGRID_API_KEY' ])
366+ client = SendGrid ::Client .new (api_key: ENV [' SENDGRID_API_KEY' ])
359367
360368from = SendGrid ::Email .new (' test@example.com' , ' Example User' )
361369to = SendGrid ::Email .new (' test@example.com' , ' Example User' )
362370subject = ' Sending with SendGrid is Fun'
363371plain_text_content = ' and easy to do anywhere, even with Ruby'
364372html_content = ' <strong>and easy to do anywhere, even with Ruby</strong>'
365- msg = SendGrid ::SendGridMessage .new (from, to, subject, plain_text_content, html_content)
373+ msg = SendGrid ::Message .new (from, to, subject, plain_text_content, html_content)
366374
367375substitutions = [
368376 ' -name-' => ' Example User' ,
0 commit comments