2017-12-26 13:25:10 +00:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
|
|
|
// jshint ignore:start
|
|
|
|
|
|
|
|
package mail
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
"github.com/documize/community/domain/smtp"
|
2017-12-26 13:25:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DocumentApprover notifies user who has just been granted document approval rights.
|
2018-05-03 18:03:25 +01:00
|
|
|
func (m *Mailer) DocumentApprover(recipient, inviterName, inviterEmail, url, document string) {
|
2017-12-26 13:25:10 +00:00
|
|
|
method := "DocumentApprover"
|
2018-03-07 18:52:19 +00:00
|
|
|
m.Initialize()
|
2017-12-26 13:25:10 +00:00
|
|
|
|
|
|
|
// check inviter name
|
2018-05-03 18:03:25 +01:00
|
|
|
if inviterName == "Hello You" || len(inviterName) == 0 {
|
|
|
|
inviterName = "Your colleague"
|
2017-12-26 13:25:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
em := smtp.EmailMessage{}
|
2018-05-03 18:03:25 +01:00
|
|
|
em.Subject = fmt.Sprintf("%s has granted you document approval", inviterName)
|
2018-03-07 18:52:19 +00:00
|
|
|
em.ToEmail = recipient
|
|
|
|
em.ToName = recipient
|
2018-05-03 18:03:25 +01:00
|
|
|
em.ReplyTo = inviterEmail
|
|
|
|
em.ReplyName = inviterName
|
2017-12-26 13:25:10 +00:00
|
|
|
|
2019-04-16 12:53:22 +01:00
|
|
|
if IsBlockedEmailDomain(em.ToEmail) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-26 13:25:10 +00:00
|
|
|
parameters := struct {
|
2018-06-13 12:47:06 +01:00
|
|
|
Subject string
|
|
|
|
Inviter string
|
|
|
|
URL string
|
|
|
|
Document string
|
|
|
|
SenderEmail string
|
2017-12-26 13:25:10 +00:00
|
|
|
}{
|
2018-03-07 18:52:19 +00:00
|
|
|
em.Subject,
|
2018-05-03 18:03:25 +01:00
|
|
|
inviterName,
|
2017-12-26 13:25:10 +00:00
|
|
|
url,
|
|
|
|
document,
|
2018-06-13 12:47:06 +01:00
|
|
|
m.Config.SenderEmail,
|
2017-12-26 13:25:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
html, err := m.ParseTemplate("mail/document-approver.html", parameters)
|
|
|
|
if err != nil {
|
|
|
|
m.Runtime.Log.Error(fmt.Sprintf("%s - unable to load email template", method), err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
em.BodyHTML = html
|
2017-12-26 13:25:10 +00:00
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
ok, err := smtp.SendMessage(m.Dialer, m.Config, em)
|
2017-12-26 13:25:10 +00:00
|
|
|
if err != nil {
|
|
|
|
m.Runtime.Log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
|
|
|
}
|
2018-03-07 18:52:19 +00:00
|
|
|
if !ok {
|
2018-10-23 13:46:38 +01:00
|
|
|
m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email", method))
|
2018-03-07 18:52:19 +00:00
|
|
|
}
|
2017-12-26 13:25:10 +00:00
|
|
|
}
|