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.
|
|
|
|
func (m *Mailer) ShareSpaceExistingUser(recipient, inviter, url, folder, intro string) {
|
|
|
|
method := "ShareSpaceExistingUser"
|
2018-03-07 18:52:19 +00:00
|
|
|
m.Initialize()
|
2017-12-26 13:25:10 +00:00
|
|
|
|
|
|
|
// check inviter name
|
|
|
|
if inviter == "Hello You" || len(inviter) == 0 {
|
|
|
|
inviter = "Your colleague"
|
|
|
|
}
|
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
em := smtp.EmailMessage{}
|
|
|
|
em.Subject = fmt.Sprintf("%s has shared %s with you", inviter, folder)
|
|
|
|
em.ToEmail = recipient
|
|
|
|
em.ToName = recipient
|
2017-12-26 13:25:10 +00:00
|
|
|
|
|
|
|
parameters := struct {
|
|
|
|
Subject string
|
|
|
|
Inviter string
|
2018-03-07 18:52:19 +00:00
|
|
|
URL string
|
2017-12-26 13:25:10 +00:00
|
|
|
Folder string
|
|
|
|
Intro string
|
|
|
|
}{
|
2018-03-07 18:52:19 +00:00
|
|
|
em.Subject,
|
2017-12-26 13:25:10 +00:00
|
|
|
inviter,
|
|
|
|
url,
|
|
|
|
folder,
|
|
|
|
intro,
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email"))
|
|
|
|
}
|
2017-12-26 13:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ShareSpaceNewUser invites new user providing Credentials, explaining the product and stating who is inviting them.
|
|
|
|
func (m *Mailer) ShareSpaceNewUser(recipient, inviter, url, space, invitationMessage string) {
|
|
|
|
method := "ShareSpaceNewUser"
|
2018-03-07 18:52:19 +00:00
|
|
|
m.Initialize()
|
2017-12-26 13:25:10 +00:00
|
|
|
|
|
|
|
// check inviter name
|
|
|
|
if inviter == "Hello You" || len(inviter) == 0 {
|
|
|
|
inviter = "Your colleague"
|
|
|
|
}
|
|
|
|
|
2018-03-07 18:52:19 +00:00
|
|
|
em := smtp.EmailMessage{}
|
|
|
|
em.Subject = fmt.Sprintf("%s has shared %s with you on Documize", inviter, space)
|
|
|
|
em.ToEmail = recipient
|
|
|
|
em.ToName = recipient
|
2017-12-26 13:25:10 +00:00
|
|
|
|
|
|
|
parameters := struct {
|
|
|
|
Subject string
|
|
|
|
Inviter string
|
2018-03-07 18:52:19 +00:00
|
|
|
URL string
|
2017-12-26 13:25:10 +00:00
|
|
|
Invitation string
|
|
|
|
Folder string
|
|
|
|
}{
|
2018-03-07 18:52:19 +00:00
|
|
|
em.Subject,
|
2017-12-26 13:25:10 +00:00
|
|
|
inviter,
|
|
|
|
url,
|
|
|
|
invitationMessage,
|
|
|
|
space,
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email"))
|
|
|
|
}
|
2017-12-26 13:25:10 +00:00
|
|
|
}
|