SendGrid client library to send emails very easily using Pharo Smalltalk.
Forked from sendgrid-smalltalk.
- V3 API (adding!)
- Send
- Blocks and Spam report
- Substitision, Personalization and Dynamic Templates
- Web API's Mail
- Marketing Email API (supported Categories, Emails, Lists)
- Pharo 5.0, 6.0, 6.1
Metacello new
baseline: 'SendGrid';
repository: 'github://sorabito/sendgrid-smalltalk/pharo-repository';
load.
SGSettings default v3ApiKey: 'SG.xxxxxxxxxxxxxxxxx'.
mail := SGMail default.
mail from: '[email protected]'.
mail fromName: 'Smalltalker'.
mail to: '[email protected]'.
mail subject:'SendGrid Test Mail'.
mail text:'My first email through SendGrid. Sent from Pharo Smalltalk.'.
mail send.
mail := SGMail default.
mail from: '[email protected]'.
mail fromName: 'Smalltalker'.
mail to: '[email protected]'.
mail subject:'SendGrid Test Mail'.
mail html:'<h1>My first email through SendGrid</h1><p>Sent from Pharo Smalltalk</p>'.
mail send.
You can send sophisticated e-mails using registered handlebars templates.
template := (SGMailTemplate name: 'SampleMail-1') ensureRegistered.
template ensureVersionNamed: 'v1' setting: [:v |
v subject: '{{event}} ({{date}})'.
v textContent: '
{{initialGreetings}}!
{{body}}
---
{{signature}}'.
]. "-> SGMailTemplate('d-18e84a9799fa4885b11d34a84e9e2384','SampleMail-1')"
mail := SGMail default.
mail allDynamicTemplates. "-> an Array(SGMailTemplate('d-18e84a9799fa4885b11d34a84e9e2384','SampleMail-1'))"
mailTemplate := mail templateNamed: 'SampleMail-1'.
mailTemplate versions. "-> an OrderedCollection(*SGMailTemplateVersion('c255155a-8fc5-471b-82cf-6e5192073245','v1'))"
mailTemplateVersion := mailTemplate activeVersion. " -> *SGMailTemplateVersion('c255155a-8fc5-471b-82cf-6e5192073245','v1')"
mailTemplateVersion loadContents textContent. "-> returns a template text content registered above"
mail := SGMail forDynamicTemplate.
mail fromName: 'Info'.
mail from: '[email protected]'.
mail addPersonalizationDo: [ :p |
p addToEntryDo: [ :ent | ent address: '[email protected]'; name: 'AAA'].
p templateData: {
'event' -> 'Smalltalk-meetup'.
'date' -> '2019/03/10'.
'initialGreetings' -> ('Hello ', p to first name).
'body' -> 'aaaaa'.
'signature' -> '[:masashi | ^umezawa]'.
} asDictionary
].
mail addPersonalizationDo: [ :p |
p addToEntryDo: [ :ent | ent address: '[email protected]'; name: 'BBB'].
p templateData: {
'event' -> 'Smalltalk-auction'.
'date' -> '2019/03/12'.
'initialGreetings' -> ('Hello ', p to first name).
'body' -> 'bbbbb'.
'signature' -> '-- MU'.
} asDictionary
].
mail sendByTemplateNamed: 'SampleMail-1'.
sg := (SGMEAPILists apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password').
sg add:'foobar'. "print it ==> a JsonObject('message'->'success' )"
sg := (SGMEAPILists apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password').
sg renameListFrom: 'foobar' to: 'foobar2'.
(SGMEAPILists apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password') get.
(SGMEAPILists apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password')
delete:'foobar'.
json := JsonObject new.
json at:'name' put:'test'.
json at:'email' put:'[email protected]'.
(SGMEAPICategories apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password')
list: 'foobar';
datum: (Array with: json asJsonString); add.
(SGMEAPICategories apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password')
list: 'foobar'; get.
(SGMEAPICategories apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password')
list: 'foobar'; count.
(SGMEAPICategories apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password')
list: 'foobar';
email:'[email protected]';
delete.
(SGMEAPICategories apiUser: 'your_sendgrid_username' apiKey:'your_sendgrid_password') list.