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

Added SendGrid output binding for sending emails #308

Merged
merged 12 commits into from
Apr 23, 2020
Merged

Added SendGrid output binding for sending emails #308

merged 12 commits into from
Apr 23, 2020

Conversation

benc-uk
Copy link
Contributor

@benc-uk benc-uk commented Apr 15, 2020

Description

Added an output binding for SendGrid
This sends simple HTML emails using the SendGrid API.

Example component

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: sendgrid
spec:
  type: bindings.twilio.sendgrid
  metadata:
  - name: emailFrom
    value: "testapp@dapr.io" # optional 
  - name: emailTo
    value: "dave@dapr.io" # optional 
  - name: subject
    value: "Hello!" # optional 
  - name: apiKey
    value: "CHANGEME" # required, this is your SendGrid key

The data field in the binding request is used as email body
You can specify any of the metadata properties on the request too (e.g. emailFrom, emailTo, subject)

Example payload

{
  "metadata": {
    "emailTo": "changeme@example.net",
    "subject": "An email from Dapr SendGrid binding"
  }, 
  "data": "<h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!"
}

Test / demo app is here https://github.com/benc-uk/dapr-sendgrid-test

TODO: Add docs :)

Issue reference

Fixes #314

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

@benc-uk benc-uk changed the title Added SendGrid output binding Added SendGrid output binding for sending emails Apr 15, 2020
@yaron2
Copy link
Member

yaron2 commented Apr 15, 2020

@jjcollinge do you mind reviewing this?

@jjcollinge
Copy link
Contributor

@yaron2 yh np - will do tomorrow

Copy link
Contributor

@jjcollinge jjcollinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few comments

bindings/sendgrid/sendgrid.go Outdated Show resolved Hide resolved
Removed duped line, and logging, normalised error messages
@jjcollinge
Copy link
Contributor

LGTM - just need to decide on whether this lives under /bindings/twilio/sendgrid/sendgrid.go or just /bindings/sendgrid/sendgrid.go - I'll leave that to @yaron2

Copy link
Member

@yaron2 yaron2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following:

/twilio/sms.go
/twilio/sendgrid.go

@benc-uk
Copy link
Contributor Author

benc-uk commented Apr 17, 2020

Moved the sms and sendgrid bindings into a twilio folder
Changed the component registration to bindings.twilio.sendgrid

The registration in daprd main.go now looks like

import(
	"github.com/dapr/components-contrib/bindings/twilio/sms"
	"github.com/dapr/components-contrib/bindings/twilio/sendgrid"
)

... ... ...

bindings_loader.NewOutput("twilio.sms", func() bindings.OutputBinding {
  return sms.NewSMS(logContrib)
}),
bindings_loader.NewOutput("twilio.sendgrid", func() bindings.OutputBinding {
  return sendgrid.NewSendGrid(logContrib)
})

Tested and working

@jjcollinge
Copy link
Contributor

Moved the sms and sendgrid bindings into a twilio folder
Changed the component registration to bindings.twilio.sendgrid

The registration in daprd main.go now looks like

import(
	"github.com/dapr/components-contrib/bindings/twilio/sms"
	"github.com/dapr/components-contrib/bindings/twilio/sendgrid"
)

... ... ...

bindings_loader.NewOutput("twilio.sms", func() bindings.OutputBinding {
  return sms.NewSMS(logContrib)
}),
bindings_loader.NewOutput("twilio.sendgrid", func() bindings.OutputBinding {
  return sendgrid.NewSendGrid(logContrib)
})

Tested and working

Cool, thanks

bindings/twilio/sendgrid/sendgrid.go Outdated Show resolved Hide resolved
// Licensed under the MIT License.
// ------------------------------------------------------------

package sendgrid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a doc issue for this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking do you want me to set up a PR with some extra docs, or just an issue to discuss it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc issue to start with. PR would be great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amanbha Hi, I've created a PR for the docs. Let me know if you need an issue to track it too dapr/docs#535

Copy link
Contributor

@amanbha amanbha Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @benc-uk Thanks. I will merge it shortly, please make the corresponding changes in dapr runtime as well.

@benc-uk benc-uk mentioned this pull request Apr 21, 2020
3 tasks
@amanbha amanbha self-requested a review April 21, 2020 18:47
@amanbha amanbha requested a review from yaron2 April 21, 2020 18:47
@yaron2
Copy link
Member

yaron2 commented Apr 21, 2020

Is sendgrid.go still under /sendgrid? It should move under /twilio/sendgrid.go

@yaron2
Copy link
Member

yaron2 commented Apr 21, 2020

And /twilio/sms.go

@benc-uk
Copy link
Contributor Author

benc-uk commented Apr 21, 2020

@yaron2 I moved them around #308 (comment)

@yaron2
Copy link
Member

yaron2 commented Apr 21, 2020

Ahh.. just to be clear I'm not hallucinating :)

Is it under /twilio/sendgrid.go? Or /twilio/sendgrid/sendgrid.go? It should be the former

@benc-uk
Copy link
Contributor Author

benc-uk commented Apr 21, 2020

twilio/sms/sms.go
and
twilio/sendgrid/sendgrid.go

This is the convention used by all the other directories that have multiple bindings. e.g. azure, aws, gcp

Otherwise we have two differently named packages in the same directory, which feels wrong

@yaron2
Copy link
Member

yaron2 commented Apr 23, 2020

LGTM

@yaron2 yaron2 merged commit ebf31ef into dapr:master Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SendGrid output binding for sending emails
4 participants