| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package email
- import (
- "os"
- "github.com/sendgrid/sendgrid-go"
- "github.com/sendgrid/sendgrid-go/helpers/mail"
- )
- type SendgridClient struct {
- APIKey string
- PWResetTemplateID string
- PWGHTemplateID string
- VerifyEmailTemplateID string
- ProjectInviteTemplateID string
- SenderEmail string
- }
- func (client *SendgridClient) SendPWResetEmail(url, email string) error {
- request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
- request.Method = "POST"
- sgMail := &mail.SGMailV3{
- Personalizations: []*mail.Personalization{
- {
- To: []*mail.Email{
- {
- Address: email,
- },
- },
- DynamicTemplateData: map[string]interface{}{
- "url": url,
- "email": email,
- },
- },
- },
- From: &mail.Email{
- Address: client.SenderEmail,
- Name: "Porter",
- },
- TemplateID: client.PWResetTemplateID,
- }
- request.Body = mail.GetRequestBody(sgMail)
- _, err := sendgrid.API(request)
- return err
- }
- func (client *SendgridClient) SendGHPWEmail(url, email string) error {
- request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
- request.Method = "POST"
- sgMail := &mail.SGMailV3{
- Personalizations: []*mail.Personalization{
- {
- To: []*mail.Email{
- {
- Address: email,
- },
- },
- DynamicTemplateData: map[string]interface{}{
- "url": url,
- "email": email,
- },
- },
- },
- From: &mail.Email{
- Address: client.SenderEmail,
- Name: "Porter",
- },
- TemplateID: client.PWGHTemplateID,
- }
- request.Body = mail.GetRequestBody(sgMail)
- _, err := sendgrid.API(request)
- return err
- }
- func (client *SendgridClient) SendEmailVerification(url, email string) error {
- request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
- request.Method = "POST"
- sgMail := &mail.SGMailV3{
- Personalizations: []*mail.Personalization{
- {
- To: []*mail.Email{
- {
- Address: email,
- },
- },
- DynamicTemplateData: map[string]interface{}{
- "url": url,
- "email": email,
- },
- },
- },
- From: &mail.Email{
- Address: client.SenderEmail,
- Name: "Porter",
- },
- TemplateID: client.VerifyEmailTemplateID,
- }
- request.Body = mail.GetRequestBody(sgMail)
- _, err := sendgrid.API(request)
- 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"
- 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
- }
|