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
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// ShareSpaceExistingUser provides an existing user with a link to a newly shared space.
|
2018-05-03 18:03:25 +01:00
|
|
|
func (m *Mailer) ShareSpaceExistingUser(recipient, inviterName, inviterEmail, url, folder, intro string) {
|
2017-12-26 13:25:10 +00:00
|
|
|
method := "ShareSpaceExistingUser"
|
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 shared %s with you", inviterName, folder)
|
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
|
|
|
|
Folder string
|
|
|
|
Intro 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,
|
|
|
|
folder,
|
|
|
|
intro,
|
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/share-space-existing-user.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 {
|
2019-04-16 12:53:22 +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
|
|
|
}
|
|
|
|
|
|
|
|
// ShareSpaceNewUser invites new user providing Credentials, explaining the product and stating who is inviting them.
|
2018-05-03 18:03:25 +01:00
|
|
|
func (m *Mailer) ShareSpaceNewUser(recipient, inviterName, inviterEmail, url, space, invitationMessage string) {
|
2017-12-26 13:25:10 +00:00
|
|
|
method := "ShareSpaceNewUser"
|
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 shared %s with you on Documize", inviterName, space)
|
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
|
|
|
|
Invitation string
|
|
|
|
Folder 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,
|
|
|
|
invitationMessage,
|
|
|
|
space,
|
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/share-space-new-user.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 {
|
2019-04-16 12:53:22 +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
|
|
|
}
|