diff --git a/api4/cloud.go b/api4/cloud.go index c625779d22..fd777f5567 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -421,6 +421,11 @@ func handleCWSWebhook(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = appErr return } + case model.EventTypeTrialEnded: + if appErr := c.App.SendCloudTrialEndedEmail(); appErr != nil { + c.Err = appErr + return + } default: c.Err = model.NewAppError("Api4.handleCWSWebhook", "api.cloud.cws_webhook_event_missing_error", nil, "", http.StatusNotFound) diff --git a/app/app_iface.go b/app/app_iface.go index 86c1299725..be0f0243ee 100644 --- a/app/app_iface.go +++ b/app/app_iface.go @@ -952,6 +952,7 @@ type AppIface interface { SendAutoResponse(channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError) SendAutoResponseIfNecessary(channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model.AppError + SendCloudTrialEndedEmail() *model.AppError SendEmailVerification(user *model.User, newEmail, redirect string) *model.AppError SendEphemeralPost(userID string, post *model.Post) *model.Post SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) diff --git a/app/cloud.go b/app/cloud.go index 10648fb835..2c70d3b63e 100644 --- a/app/cloud.go +++ b/app/cloud.go @@ -186,7 +186,11 @@ func (a *App) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model countNotOks := 0 for admin := range sysAdmins { - err := a.Srv().EmailService.SendCloudTrialEndWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Username, trialEndDate, sysAdmins[admin].Locale, siteURL) + name := sysAdmins[admin].FirstName + if name == "" { + name = sysAdmins[admin].Username + } + err := a.Srv().EmailService.SendCloudTrialEndWarningEmail(sysAdmins[admin].Email, name, trialEndDate, sysAdmins[admin].Locale, siteURL) if err != nil { a.Log().Error("Error sending trial ending warning to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err)) countNotOks++ @@ -200,3 +204,33 @@ func (a *App) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model return nil } + +func (a *App) SendCloudTrialEndedEmail() *model.AppError { + sysAdmins, e := a.getSysAdminsEmailRecipients() + if e != nil { + return e + } + + // we want to at least have one email sent out to an admin + countNotOks := 0 + + for admin := range sysAdmins { + name := sysAdmins[admin].FirstName + if name == "" { + name = sysAdmins[admin].Username + } + + err := a.Srv().EmailService.SendCloudTrialEndedEmail(sysAdmins[admin].Email, name, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL) + if err != nil { + a.Log().Error("Error sending trial ended email to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err)) + countNotOks++ + } + } + + // if not even one admin got an email, we consider that this operation errored + if countNotOks == len(sysAdmins) { + return model.NewAppError("app.SendCloudTrialEndedEmail", "app.user.send_emails.app_error", nil, "", http.StatusInternalServerError) + } + + return nil +} diff --git a/app/email.go b/app/email.go index e34cf9bf47..15045b6cac 100644 --- a/app/email.go +++ b/app/email.go @@ -290,13 +290,13 @@ func (es *EmailService) sendWelcomeEmail(userID string, email string, verified b return nil } -func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, userName, trialEndDate, locale, siteURL string) *model.AppError { +func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, name, trialEndDate, locale, siteURL string) *model.AppError { T := i18n.GetUserTranslations(locale) subject := T("api.templates.cloud_trial_ending_email.subject") data := es.newEmailTemplateData(locale) data.Props["Title"] = T("api.templates.cloud_trial_ending_email.title") - data.Props["SubTitle"] = T("api.templates.cloud_trial_ending_email.subtitle", map[string]interface{}{"Username": userName, "TrialEnd": trialEndDate}) + data.Props["SubTitle"] = T("api.templates.cloud_trial_ending_email.subtitle", map[string]interface{}{"Name": name, "TrialEnd": trialEndDate}) data.Props["SiteURL"] = siteURL data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription", siteURL) data.Props["Button"] = T("api.templates.cloud_trial_ending_email.add_payment_method") @@ -314,6 +314,33 @@ func (es *EmailService) SendCloudTrialEndWarningEmail(userEmail, userName, trial return nil } +func (es *EmailService) SendCloudTrialEndedEmail(userEmail, name, locale, siteURL string) *model.AppError { + T := i18n.GetUserTranslations(locale) + subject := T("api.templates.cloud_trial_ended_email.subject") + + t := time.Now() + todayDate := fmt.Sprintf("%s %d, %d", t.Month(), t.Day(), t.Year()) + + data := es.newEmailTemplateData(locale) + data.Props["Title"] = T("api.templates.cloud_trial_ended_email.title") + data.Props["SubTitle"] = T("api.templates.cloud_trial_ended_email.subtitle", map[string]interface{}{"Name": name, "TodayDate": todayDate}) + data.Props["SiteURL"] = siteURL + data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription", siteURL) + data.Props["Button"] = T("api.templates.cloud_trial_ended_email.start_subscription") + data.Props["QuestionTitle"] = T("api.templates.questions_footer.title") + data.Props["QuestionInfo"] = T("api.templates.questions_footer.info") + + body, err := es.srv.TemplatesContainer().RenderToString("cloud_trial_ended_email", data) + if err != nil { + return model.NewAppError("SendCloudTrialEndedEmail", "api.user.cloud_trial_ended_email.error", nil, err.Error(), http.StatusInternalServerError) + } + + if err := es.sendMail(userEmail, subject, body); err != nil { + return model.NewAppError("SendCloudTrialEndedEmail", "api.user.cloud_trial_ended_email.error", nil, err.Error(), http.StatusInternalServerError) + } + return nil +} + // SendCloudWelcomeEmail sends the cloud version of the welcome email func (es *EmailService) SendCloudWelcomeEmail(userEmail, locale, teamInviteID, workSpaceName, dns, siteURL string) *model.AppError { T := i18n.GetUserTranslations(locale) diff --git a/app/opentracing/opentracing_layer.go b/app/opentracing/opentracing_layer.go index bdf5c8d15e..7dfdc58ebc 100644 --- a/app/opentracing/opentracing_layer.go +++ b/app/opentracing/opentracing_layer.go @@ -14125,6 +14125,28 @@ func (a *OpenTracingAppLayer) SendCloudTrialEndWarningEmail(trialEndDate string, return resultVar0 } +func (a *OpenTracingAppLayer) SendCloudTrialEndedEmail() *model.AppError { + origCtx := a.ctx + span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendCloudTrialEndedEmail") + + a.ctx = newCtx + a.app.Srv().Store.SetContext(newCtx) + defer func() { + a.app.Srv().Store.SetContext(origCtx) + a.ctx = origCtx + }() + + defer span.Finish() + resultVar0 := a.app.SendCloudTrialEndedEmail() + + if resultVar0 != nil { + span.LogFields(spanlog.Error(resultVar0)) + ext.Error.Set(span, true) + } + + return resultVar0 +} + func (a *OpenTracingAppLayer) SendEmailVerification(user *model.User, newEmail string, redirect string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendEmailVerification") diff --git a/i18n/en.json b/i18n/en.json index fc16d410c6..2b17c3bfba 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3126,6 +3126,22 @@ "id": "api.templates.at_limit_title", "translation": "You’ve reached the user limit for the free tier " }, + { + "id": "api.templates.cloud_trial_ended_email.start_subscription", + "translation": "Start subscription" + }, + { + "id": "api.templates.cloud_trial_ended_email.subject", + "translation": "Mattermost cloud trial has ended" + }, + { + "id": "api.templates.cloud_trial_ended_email.subtitle", + "translation": "{{.Name}}, your 14-day free trial of Mattermost Cloud Professional ends today {{.TodayDate}}. Please add your payment information to ensure your team can continue enjoying the benefits of Cloud Professional." + }, + { + "id": "api.templates.cloud_trial_ended_email.title", + "translation": "Your free 14-day trial of Mattermost ends today" + }, { "id": "api.templates.cloud_trial_ending_email.add_payment_method", "translation": "Add Payment method" @@ -3136,7 +3152,7 @@ }, { "id": "api.templates.cloud_trial_ending_email.subtitle", - "translation": "{{.Username}}, your 14-day trial of Mattermost Cloud Professional is ending in 3 days, on {{.TrialEnd}}. Please add your payment information to ensure your team can continue enjoying the benefits of Cloud Professional." + "translation": "{{.Name}}, your 14-day trial of Mattermost Cloud Professional is ending in 3 days, on {{.TrialEnd}}. Please add your payment information to ensure your team can continue enjoying the benefits of Cloud Professional." }, { "id": "api.templates.cloud_trial_ending_email.title", @@ -3846,6 +3862,10 @@ "id": "api.user.check_user_password.invalid.app_error", "translation": "Login failed because of invalid password." }, + { + "id": "api.user.cloud_trial_ended_email.error", + "translation": "Failed to send trial ended email" + }, { "id": "api.user.cloud_trial_ending_email.error", "translation": "Failed to send trial ending warning email" diff --git a/model/cloud.go b/model/cloud.go index 0fe6c6a79a..b9596cc294 100644 --- a/model/cloud.go +++ b/model/cloud.go @@ -10,6 +10,7 @@ const ( EventTypeFailedPaymentNoCard = "failed-payment-no-card" EventTypeSendAdminWelcomeEmail = "send-admin-welcome-email" EventTypeTrialWillEnd = "trial-will-end" + EventTypeTrialEnded = "trial-ended" JoinLimitation = "join" InviteLimitation = "invite" ) diff --git a/templates/cloud_trial_ended_email.html b/templates/cloud_trial_ended_email.html new file mode 100644 index 0000000000..b101f6c97a --- /dev/null +++ b/templates/cloud_trial_ended_email.html @@ -0,0 +1,442 @@ +{{define "cloud_trial_ended_email"}} + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + +
+ + + + + + +
+ +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + + +
+
{{.Props.Title}}
+
+
{{.Props.SubTitle}}
+
+ + + + +
+ + {{.Props.Button}} + +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + +
+ + + + + + +
+ +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + + + + +
+
{{.Props.QuestionTitle}}
+
+
{{.Props.QuestionInfo}} + + {{.Props.SupportEmail}} + +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + +
+
{{.Props.Organization}} + {{.Props.FooterV2}} +
+
+
+ +
+
+ +
+
+ +
+ + + + +{{end}} diff --git a/templates/cloud_trial_ended_email.mjml b/templates/cloud_trial_ended_email.mjml new file mode 100644 index 0000000000..1682853216 --- /dev/null +++ b/templates/cloud_trial_ended_email.mjml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + {{.Props.Title}} + + + {{.Props.SubTitle}} + + + {{.Props.Button}} + + + + + + + + + + + + + + {{.Props.QuestionTitle}} + + + {{.Props.QuestionInfo}} + + {{.Props.SupportEmail}} + + + + + + + + + {{.Props.Organization}} + {{.Props.FooterV2}} + + + + + + + +