Skip to content

Commit

Permalink
add welcome mail after activation
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Nov 23, 2021
1 parent ac2ec3f commit 1330571
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
22 changes: 21 additions & 1 deletion backend/api/signup/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (r *Signup) Activate(ctx context.Context, req signup.ActivateRequest) (stri
return "", internalServerError
}

if err := r.sendWelcomeMail(rec.Email, rec.Name); err != nil {
log.Printf("failed to sedn welcome mail error %s", err)
// do nothing, not critical
}

return token, nil
}

Expand All @@ -143,14 +148,29 @@ func rawRequest(ctx context.Context) []byte {

func (r *Signup) sendActivationCode(email, name, activationCode string) error {
toEmail := email
fromEmail := texts.ActivationMailFrom
fromEmail := texts.MailFrom
subject := texts.ActivationMailSubject
body, err := texts.ActivationMailBody(name, activationCode)
if err != nil {
log.Printf("failed to get mail body: %s", err)
return err
}
return r.sendEmail(fromEmail, toEmail, subject, body)
}

func (r Signup) sendWelcomeMail(email, name string) error {
toEmail := email
fromEmail := texts.MailFrom
subject := texts.WelcomeMailSubject
body, err := texts.WelcomeMailBody(name)
if err != nil {
log.Printf("failed to get mail body: %s", err)
return err
}
return r.sendEmail(fromEmail, toEmail, subject, body)
}

func (r *Signup) sendEmail(fromEmail, toEmail, subject, body string) error {
cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
log.Printf("failed to load configuration: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions backend/config/state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ stages:
REPORT_BUCKET: mantil-user-reports
SLACK_WEBHOOK: https://hooks.slack.com/services/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
- name: signup
hash: 4ae7e0e9
s3_key: functions/backend/production/signup-4ae7e0e9.zip
hash: 1aa42937
s3_key: functions/backend/production/signup-1aa42937.zip
memory_size: 128
timeout: 900
env:
Expand Down
25 changes: 20 additions & 5 deletions texts/texts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@ import (
"text/template"
)

const ActivationMailFrom = "[email protected]"
const MailFrom = "[email protected]"
const ActivationMailSubject = "Mantil activation instructions"
const WelcomeMailSubject = "Welcome to Mantil!"

//go:embed activationMailBody
var activationMailBodyTemplate string

//go:embed welcomeMailBody
var welcomeMailBodyTemplate string

func ActivationMailBody(name, activationCode string) (string, error) {
data := struct {
Name string
ActivationCode string
}{name, activationCode}

tpl, err := template.New("").Parse(activationMailBodyTemplate)
return renderTemplate(data, activationMailBodyTemplate)
}

const NotActivatedError = `Mantil is not activated. Please fill out the short survey at
www.mantil.com to receive your activation code.`

func WelcomeMailBody(name string) (string, error) {
data := struct {
Name string
}{name}
return renderTemplate(data, welcomeMailBodyTemplate)
}

func renderTemplate(data interface{}, content string) (string, error) {
tpl, err := template.New("").Parse(content)
if err != nil {
return "", err
}
Expand All @@ -28,6 +46,3 @@ func ActivationMailBody(name, activationCode string) (string, error) {
}
return buf.String(), nil
}

const NotActivatedError = `Mantil is not activated. Please fill out the short survey at
www.mantil.com to receive your activation code.`
5 changes: 5 additions & 0 deletions texts/welcomeMailBody
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hi {{.Name}},

Welcome to Mantil!

The Mantil Team

0 comments on commit 1330571

Please sign in to comment.