|
|
|
|
@@ -27,6 +27,15 @@ import (
|
|
|
|
|
|
|
|
|
|
const serverInactivityHours = 100
|
|
|
|
|
|
|
|
|
|
// Returns category if enabled is true (default false)
|
|
|
|
|
// If "" is returned when enabled is false, the category headers aren't attached to the email
|
|
|
|
|
func getSendGridCategory(category string, enabled bool) string {
|
|
|
|
|
if enabled {
|
|
|
|
|
return category
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) SendChangeUsernameEmail(newUsername, email, locale, siteURL string) error {
|
|
|
|
|
T := i18n.GetUserTranslations(locale)
|
|
|
|
|
|
|
|
|
|
@@ -46,7 +55,7 @@ func (es *Service) SendChangeUsernameEmail(newUsername, email, locale, siteURL s
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "ChangeUsernameEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -79,7 +88,7 @@ func (es *Service) SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, tok
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(newUserEmail, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(newUserEmail, subject, body, "EmailChangeVerifyEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -105,7 +114,7 @@ func (es *Service) SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL stri
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(oldEmail, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(oldEmail, subject, body, "EmailChangeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -143,7 +152,7 @@ func (es *Service) SendVerifyEmail(userEmail, locale, siteURL, token, redirect s
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(userEmail, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(userEmail, subject, body, "VerifyEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -168,7 +177,7 @@ func (es *Service) SendSignInChangeEmail(email, method, locale, siteURL string)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "SignInChangeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -226,7 +235,7 @@ func (es *Service) SendWelcomeEmail(userID string, email string, verified bool,
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "WelcomeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -259,11 +268,11 @@ func (es *Service) SendCloudUpgradeConfirmationEmail(userEmail, name, date, loca
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if isYearly {
|
|
|
|
|
if err := es.SendMailWithEmbeddedFilesAndCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail, embeddedFiles); err != nil {
|
|
|
|
|
if err := es.SendMailWithEmbeddedFilesAndCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail, embeddedFiles, "CloudUpgradeConfirmationEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail, "CloudUpgradeConfirmationEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -304,7 +313,7 @@ func (es *Service) SendCloudWelcomeEmail(userEmail, locale, teamInviteID, workSp
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail, "CloudWelcomeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -330,7 +339,7 @@ func (es *Service) SendPasswordChangeEmail(email, method, locale, siteURL string
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "PasswordChangeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -355,7 +364,7 @@ func (es *Service) SendUserAccessTokenAddedEmail(email, locale, siteURL string)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "UserAccessTokenAddedEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -385,7 +394,7 @@ func (es *Service) SendPasswordResetEmail(email string, token *model.Token, loca
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "PasswordResetEmail"); err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -415,7 +424,7 @@ func (es *Service) SendMfaChangeEmail(email string, activated bool, locale, site
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "MfaChangeEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -501,7 +510,7 @@ func (es *Service) SendInviteEmails(
|
|
|
|
|
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(invite, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(invite, subject, body, "InviteEmail"); err != nil {
|
|
|
|
|
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
|
|
|
|
if errorWhenNotSent {
|
|
|
|
|
return SendMailError
|
|
|
|
|
@@ -617,7 +626,7 @@ func (es *Service) SendGuestInviteEmails(
|
|
|
|
|
mlog.Error("Failed to send invite email successfully", mlog.Err(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nErr := es.SendMailWithEmbeddedFiles(invite, subject, body, embeddedFiles, "", "", ""); nErr != nil {
|
|
|
|
|
if nErr := es.SendMailWithEmbeddedFiles(invite, subject, body, embeddedFiles, "", "", "", "InviteEmail"); nErr != nil {
|
|
|
|
|
mlog.Error("Failed to send invite email successfully", mlog.Err(nErr))
|
|
|
|
|
if errorWhenNotSent {
|
|
|
|
|
return SendMailError
|
|
|
|
|
@@ -765,7 +774,7 @@ func (es *Service) SendInviteEmailsToTeamAndChannels(
|
|
|
|
|
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nErr := es.SendMailWithEmbeddedFiles(invite, subject, body, embeddedFiles, "", "", ""); nErr != nil {
|
|
|
|
|
if nErr := es.SendMailWithEmbeddedFiles(invite, subject, body, embeddedFiles, "", "", "", "InviteEmailToTeamsAndChannels"); nErr != nil {
|
|
|
|
|
mlog.Error("Failed to send invite email successfully", mlog.Err(nErr))
|
|
|
|
|
if errorWhenNotSent {
|
|
|
|
|
inviteWithError := &model.EmailInviteWithError{
|
|
|
|
|
@@ -828,7 +837,7 @@ func (es *Service) SendDeactivateAccountEmail(email string, locale, siteURL stri
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil { // this needs to receive the header options
|
|
|
|
|
if err := es.sendMail(email, subject, body, "DeactivateAccountEmail"); err != nil { // this needs to receive the header options
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -839,39 +848,47 @@ func (es *Service) SendNotificationMail(to, subject, htmlBody string) error {
|
|
|
|
|
if !*es.config().EmailSettings.SendEmailNotifications {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return es.sendMail(to, subject, htmlBody)
|
|
|
|
|
return es.sendMail(to, subject, htmlBody, "NotificationEmail")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) sendMail(to, subject, htmlBody string) error {
|
|
|
|
|
return es.sendMailWithCC(to, subject, htmlBody, "")
|
|
|
|
|
func (es *Service) sendMail(to, subject, htmlBody, category string) error {
|
|
|
|
|
return es.sendMailWithCC(to, subject, htmlBody, "", category)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) sendEmailWithCustomReplyTo(to, subject, htmlBody, replyToAddress string) error {
|
|
|
|
|
func (es *Service) sendEmailWithCustomReplyTo(to, subject, htmlBody, replyToAddress, category string) error {
|
|
|
|
|
license := es.license()
|
|
|
|
|
mailConfig := es.mailServiceConfig(replyToAddress)
|
|
|
|
|
|
|
|
|
|
return mail.SendMailUsingConfig(to, subject, htmlBody, mailConfig, license != nil && *license.Features.Compliance, "", "", "", "")
|
|
|
|
|
category = getSendGridCategory(category, license.IsCloud())
|
|
|
|
|
|
|
|
|
|
return mail.SendMailUsingConfig(to, subject, htmlBody, mailConfig, license != nil && *license.Features.Compliance, "", "", "", "", category)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) sendMailWithCC(to, subject, htmlBody string, ccMail string) error {
|
|
|
|
|
func (es *Service) sendMailWithCC(to, subject, htmlBody, ccMail, category string) error {
|
|
|
|
|
license := es.license()
|
|
|
|
|
mailConfig := es.mailServiceConfig("")
|
|
|
|
|
|
|
|
|
|
return mail.SendMailUsingConfig(to, subject, htmlBody, mailConfig, license != nil && *license.Features.Compliance, "", "", "", ccMail)
|
|
|
|
|
category = getSendGridCategory(category, license.IsCloud())
|
|
|
|
|
|
|
|
|
|
return mail.SendMailUsingConfig(to, subject, htmlBody, mailConfig, license != nil && *license.Features.Compliance, "", "", "", ccMail, category)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) SendMailWithEmbeddedFilesAndCustomReplyTo(to, subject, htmlBody, replyToAddress string, embeddedFiles map[string]io.Reader) error {
|
|
|
|
|
func (es *Service) SendMailWithEmbeddedFilesAndCustomReplyTo(to, subject, htmlBody, replyToAddress string, embeddedFiles map[string]io.Reader, category string) error {
|
|
|
|
|
license := es.license()
|
|
|
|
|
mailConfig := es.mailServiceConfig(replyToAddress)
|
|
|
|
|
|
|
|
|
|
return mail.SendMailWithEmbeddedFilesUsingConfig(to, subject, htmlBody, embeddedFiles, mailConfig, license != nil && *license.Features.Compliance, "", "", "", "")
|
|
|
|
|
category = getSendGridCategory(category, license.IsCloud())
|
|
|
|
|
|
|
|
|
|
return mail.SendMailWithEmbeddedFilesUsingConfig(to, subject, htmlBody, embeddedFiles, mailConfig, license != nil && *license.Features.Compliance, "", "", "", "", category)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader, messageID string, inReplyTo string, references string) error {
|
|
|
|
|
func (es *Service) SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader, messageID string, inReplyTo string, references string, category string) error {
|
|
|
|
|
license := es.license()
|
|
|
|
|
mailConfig := es.mailServiceConfig("")
|
|
|
|
|
|
|
|
|
|
return mail.SendMailWithEmbeddedFilesUsingConfig(to, subject, htmlBody, embeddedFiles, mailConfig, license != nil && *license.Features.Compliance, messageID, inReplyTo, references, "")
|
|
|
|
|
category = getSendGridCategory(category, license.IsCloud())
|
|
|
|
|
|
|
|
|
|
return mail.SendMailWithEmbeddedFilesUsingConfig(to, subject, htmlBody, embeddedFiles, mailConfig, license != nil && *license.Features.Compliance, messageID, inReplyTo, references, "", category)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (es *Service) InvalidateVerifyEmailTokensForUser(userID string) *model.AppError {
|
|
|
|
|
@@ -965,7 +982,7 @@ func (es *Service) SendLicenseInactivityEmail(email, name, locale, siteURL strin
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "LicenseInactivityEmail"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -993,7 +1010,7 @@ func (es *Service) SendLicenseUpForRenewalEmail(email, name, locale, siteURL, re
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "LicenseUpForRenewal"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1026,7 +1043,7 @@ func (es *Service) SendPaymentFailedEmail(email string, locale string, failedPay
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "PaymentFailed"); err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1053,7 +1070,7 @@ func (es *Service) SendNoCardPaymentFailedEmail(email string, locale string, sit
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "NoCardPaymentFailed"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1083,7 +1100,7 @@ func (es *Service) SendDelinquencyEmail7(email, locale, siteURL, planName string
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency7"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1112,7 +1129,7 @@ func (es *Service) SendDelinquencyEmail14(email, locale, siteURL, planName strin
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency14"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1142,7 +1159,7 @@ func (es *Service) SendDelinquencyEmail30(email, locale, siteURL, planName strin
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency30"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1174,7 +1191,7 @@ func (es *Service) SendDelinquencyEmail45(email, locale, siteURL, planName, deli
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency45"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1207,7 +1224,7 @@ func (es *Service) SendDelinquencyEmail60(email, locale, siteURL string) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency60"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1240,7 +1257,7 @@ func (es *Service) SendDelinquencyEmail75(email, locale, siteURL, planName, deli
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency75"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1272,7 +1289,7 @@ func (es *Service) SendDelinquencyEmail90(email, locale, siteURL string) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail); err != nil {
|
|
|
|
|
if err := es.sendEmailWithCustomReplyTo(email, subject, body, *es.config().SupportSettings.SupportEmail, "Delinquency90"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1297,7 +1314,7 @@ func (es *Service) SendRemoveExpiredLicenseEmail(renewalLink, email string, loca
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := es.sendMail(email, subject, body); err != nil {
|
|
|
|
|
if err := es.sendMail(email, subject, body, "RemoveExpiredLicense"); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|