Commit 8fb25a94 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

fix mails

parent 0676d954
Pipeline #59962 passed with stages
in 3 minutes and 6 seconds
......@@ -212,7 +212,7 @@ func CloseShare(w http.ResponseWriter, r *http.Request) *HTTPError {
}
// TODO send mail
SendMail(share)
// TODO background job
//{
// job, err := enqueuer.Enqueue("DeleteShare", nil)
......
......@@ -17,7 +17,7 @@ type Share struct {
ID uuid.UUID `json:"id" gorm:"primary_key"`
Name string `json:"name,omitempty"`
Expires *time.Time `json:"expires,omitempty"`
DownloadLimit int `json:"download_limit,omitempty"`
DownloadLimit int `json:"download_limit,omitempty"`
IsPublic bool `json:"is_public" gorm:"not null; default:false; index"`
Password string `json:"-"`
Emails []string `json:"emails,omitempty" gorm:"-"`
......
......@@ -3,20 +3,28 @@
package main
import (
"fmt"
"os"
"strings"
"github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/mail"
)
func SendMail(sh Share) error {
if len(sh.Emails) <= 0 {
return nil
}
m := mail.NewV3Mail()
m.SetFrom(mail.NewEmail(os.Getenv("SENDGRID_SENDER_NAME"), os.Getenv("SENDGRID_SENDER_MAIL")))
m.SetTemplateID(os.Getenv("SENDGRID_SHARE_TEMPLATE"))
p := mail.NewPersonalization()
receivers := []*mail.Email{
mail.NewEmail("Lukas Böhm", "lukas.l.boehm@fau.de"),
var receivers []*mail.Email
for _, address := range sh.Emails {
receivers = append(receivers, mail.NewEmail(strings.Split(address, "@")[0], address))
}
fmt.Println(sh.Emails)
p.AddTos(receivers...)
p.SetDynamicTemplateData("id", sh.ID.String())
p.SetDynamicTemplateData("download_id", sh.DownloadLimit)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment