mirror of
https://github.com/documize/community.git
synced 2025-07-26 00:29:47 +02:00
public mail methods
This commit is contained in:
parent
2e39b7a471
commit
56fe047136
2 changed files with 32 additions and 30 deletions
|
@ -20,8 +20,8 @@ import (
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/web"
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
|
"github.com/documize/community/core/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InviteNewUser invites someone new providing credentials, explaining the product and stating who is inviting them.
|
// InviteNewUser invites someone new providing credentials, explaining the product and stating who is inviting them.
|
||||||
|
@ -44,8 +44,8 @@ func InviteNewUser(recipient, inviter, url, username, password string) {
|
||||||
|
|
||||||
subject := fmt.Sprintf("%s has invited you to Documize", inviter)
|
subject := fmt.Sprintf("%s has invited you to Documize", inviter)
|
||||||
|
|
||||||
e := newEmail()
|
e := NewEmail()
|
||||||
e.From = creds.SMTPsender()
|
e.From = SMTPCreds.SMTPsender()
|
||||||
e.To = []string{recipient}
|
e.To = []string{recipient}
|
||||||
e.Subject = subject
|
e.Subject = subject
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func InviteNewUser(recipient, inviter, url, username, password string) {
|
||||||
log.IfErr(t.Execute(buffer, ¶meters))
|
log.IfErr(t.Execute(buffer, ¶meters))
|
||||||
e.HTML = buffer.Bytes()
|
e.HTML = buffer.Bytes()
|
||||||
|
|
||||||
err = e.Send(getHost(), getAuth())
|
err = e.Send(GetHost(), GetAuth())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
||||||
|
@ -95,8 +95,8 @@ func InviteExistingUser(recipient, inviter, url string) {
|
||||||
|
|
||||||
subject := fmt.Sprintf("%s has invited you to their Documize account", inviter)
|
subject := fmt.Sprintf("%s has invited you to their Documize account", inviter)
|
||||||
|
|
||||||
e := newEmail()
|
e := NewEmail()
|
||||||
e.From = creds.SMTPsender()
|
e.From = SMTPCreds.SMTPsender()
|
||||||
e.To = []string{recipient}
|
e.To = []string{recipient}
|
||||||
e.Subject = subject
|
e.Subject = subject
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func InviteExistingUser(recipient, inviter, url string) {
|
||||||
log.IfErr(t.Execute(buffer, ¶meters))
|
log.IfErr(t.Execute(buffer, ¶meters))
|
||||||
e.HTML = buffer.Bytes()
|
e.HTML = buffer.Bytes()
|
||||||
|
|
||||||
err = e.Send(getHost(), getAuth())
|
err = e.Send(GetHost(), GetAuth())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
||||||
|
@ -137,8 +137,8 @@ func PasswordReset(recipient, url string) {
|
||||||
|
|
||||||
subject := "Documize password reset request"
|
subject := "Documize password reset request"
|
||||||
|
|
||||||
e := newEmail()
|
e := NewEmail()
|
||||||
e.From = creds.SMTPsender() //e.g. "Documize <hello@documize.com>"
|
e.From = SMTPCreds.SMTPsender() //e.g. "Documize <hello@documize.com>"
|
||||||
e.To = []string{recipient}
|
e.To = []string{recipient}
|
||||||
e.Subject = subject
|
e.Subject = subject
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func PasswordReset(recipient, url string) {
|
||||||
log.IfErr(t.Execute(buffer, ¶meters))
|
log.IfErr(t.Execute(buffer, ¶meters))
|
||||||
e.HTML = buffer.Bytes()
|
e.HTML = buffer.Bytes()
|
||||||
|
|
||||||
err = e.Send(getHost(), getAuth())
|
err = e.Send(GetHost(), GetAuth())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
||||||
|
@ -182,8 +182,8 @@ func ShareFolderExistingUser(recipient, inviter, url, folder, intro string) {
|
||||||
|
|
||||||
subject := fmt.Sprintf("%s has shared %s with you", inviter, folder)
|
subject := fmt.Sprintf("%s has shared %s with you", inviter, folder)
|
||||||
|
|
||||||
e := newEmail()
|
e := NewEmail()
|
||||||
e.From = creds.SMTPsender()
|
e.From = SMTPCreds.SMTPsender()
|
||||||
e.To = []string{recipient}
|
e.To = []string{recipient}
|
||||||
e.Subject = subject
|
e.Subject = subject
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ func ShareFolderExistingUser(recipient, inviter, url, folder, intro string) {
|
||||||
log.IfErr(t.Execute(buffer, ¶meters))
|
log.IfErr(t.Execute(buffer, ¶meters))
|
||||||
e.HTML = buffer.Bytes()
|
e.HTML = buffer.Bytes()
|
||||||
|
|
||||||
err = e.Send(getHost(), getAuth())
|
err = e.Send(GetHost(), GetAuth())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
||||||
|
@ -233,8 +233,8 @@ func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage strin
|
||||||
|
|
||||||
subject := fmt.Sprintf("%s has shared %s with you on Documize", inviter, folder)
|
subject := fmt.Sprintf("%s has shared %s with you on Documize", inviter, folder)
|
||||||
|
|
||||||
e := newEmail()
|
e := NewEmail()
|
||||||
e.From = creds.SMTPsender()
|
e.From = SMTPCreds.SMTPsender()
|
||||||
e.To = []string{recipient}
|
e.To = []string{recipient}
|
||||||
e.Subject = subject
|
e.Subject = subject
|
||||||
|
|
||||||
|
@ -257,14 +257,15 @@ func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage strin
|
||||||
log.IfErr(t.Execute(buffer, ¶meters))
|
log.IfErr(t.Execute(buffer, ¶meters))
|
||||||
e.HTML = buffer.Bytes()
|
e.HTML = buffer.Bytes()
|
||||||
|
|
||||||
err = e.Send(getHost(), getAuth())
|
err = e.Send(GetHost(), GetAuth())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
log.Error(fmt.Sprintf("%s - unable to send email", method), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var creds = struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender func() string }{
|
// SMTPCreds return SMTP configuration.
|
||||||
|
var SMTPCreds = struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender func() string }{
|
||||||
func() string { return request.ConfigString("SMTP", "userid") },
|
func() string { return request.ConfigString("SMTP", "userid") },
|
||||||
func() string { return request.ConfigString("SMTP", "password") },
|
func() string { return request.ConfigString("SMTP", "password") },
|
||||||
func() string { return request.ConfigString("SMTP", "host") },
|
func() string { return request.ConfigString("SMTP", "host") },
|
||||||
|
@ -278,16 +279,16 @@ var creds = struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender fun
|
||||||
func() string { return request.ConfigString("SMTP", "sender") },
|
func() string { return request.ConfigString("SMTP", "sender") },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to return SMTP credentials
|
// GetAuth to return SMTP credentials
|
||||||
func getAuth() smtp.Auth {
|
func GetAuth() smtp.Auth {
|
||||||
a := smtp.PlainAuth("", creds.SMTPuserid(), creds.SMTPpassword(), creds.SMTPhost())
|
a := smtp.PlainAuth("", SMTPCreds.SMTPuserid(), SMTPCreds.SMTPpassword(), SMTPCreds.SMTPhost())
|
||||||
//fmt.Printf("DEBUG getAuth() = %#v\n", a)
|
//fmt.Printf("DEBUG GetAuth() = %#v\n", a)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to return SMTP host details
|
// GetHost to return SMTP host details
|
||||||
func getHost() string {
|
func GetHost() string {
|
||||||
h := creds.SMTPhost() + ":" + creds.SMTPport()
|
h := SMTPCreds.SMTPhost() + ":" + SMTPCreds.SMTPport()
|
||||||
//fmt.Printf("DEBUG getHost() = %#v\n", h)
|
//fmt.Printf("DEBUG GetHost() = %#v\n", h)
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
//
|
//
|
||||||
// This software (Documize Community Edition) is licensed under
|
// This software (Documize Community Edition) is licensed under
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
//
|
//
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
// by contacting <sales@documize.com>.
|
// by contacting <sales@documize.com>.
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/documize/community/core/log"
|
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
@ -56,6 +55,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/documize/community/core/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -77,8 +78,8 @@ type Email struct {
|
||||||
ReadReceipt []string
|
ReadReceipt []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// newEmail creates an Email, and returns the pointer to it.
|
// NewEmail creates an Email, and returns the pointer to it.
|
||||||
func newEmail() *Email {
|
func NewEmail() *Email {
|
||||||
return &Email{Headers: textproto.MIMEHeader{}}
|
return &Email{Headers: textproto.MIMEHeader{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue