|
|
@@ -1,6 +1,7 @@
|
|
|
package email
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"os"
|
|
|
|
|
|
"github.com/sendgrid/sendgrid-go"
|
|
|
@@ -8,10 +9,11 @@ import (
|
|
|
)
|
|
|
|
|
|
type SendgridClient struct {
|
|
|
- APIKey string
|
|
|
- PWResetTemplateID string
|
|
|
- VerifyEmailTemplateID string
|
|
|
- SenderEmail string
|
|
|
+ APIKey string
|
|
|
+ PWResetTemplateID string
|
|
|
+ VerifyEmailTemplateID string
|
|
|
+ ProjectInviteTemplateID string
|
|
|
+ SenderEmail string
|
|
|
}
|
|
|
|
|
|
func (client *SendgridClient) SendPWResetEmail(url, email string) error {
|
|
|
@@ -77,3 +79,38 @@ func (client *SendgridClient) SendEmailVerification(url, email string) error {
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+func (client *SendgridClient) SendProjectInviteEmail(url, project, projectOwnerEmail, email string) error {
|
|
|
+ request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
|
|
|
+ request.Method = "POST"
|
|
|
+
|
|
|
+ fmt.Println("GOT HERE", url, project, projectOwnerEmail, email)
|
|
|
+
|
|
|
+ sgMail := &mail.SGMailV3{
|
|
|
+ Personalizations: []*mail.Personalization{
|
|
|
+ {
|
|
|
+ To: []*mail.Email{
|
|
|
+ {
|
|
|
+ Address: email,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ DynamicTemplateData: map[string]interface{}{
|
|
|
+ "url": url,
|
|
|
+ "sender_email": projectOwnerEmail,
|
|
|
+ "project": project,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ From: &mail.Email{
|
|
|
+ Address: client.SenderEmail,
|
|
|
+ Name: "Porter",
|
|
|
+ },
|
|
|
+ TemplateID: client.ProjectInviteTemplateID,
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Body = mail.GetRequestBody(sgMail)
|
|
|
+
|
|
|
+ _, err := sendgrid.API(request)
|
|
|
+
|
|
|
+ return err
|
|
|
+}
|