1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/domain/mail/mailer.go

70 lines
1.8 KiB
Go
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
2016-07-20 15:58:37 +01:00
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// 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
2016-07-20 15:58:37 +01:00
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
// jshint ignore:start
package mail
import (
"net/smtp"
2017-08-17 10:34:12 +01:00
"strings"
2016-07-07 18:54:16 -07:00
2017-08-02 15:26:31 +01:00
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
2016-07-07 18:54:16 -07:00
)
2017-08-02 15:26:31 +01:00
// Mailer provides emailing facilities
type Mailer struct {
Runtime *env.Runtime
Store *domain.Store
Context domain.RequestContext
2017-08-04 13:17:09 +01:00
Credentials Credentials
2017-08-02 15:26:31 +01:00
}
2017-08-04 13:17:09 +01:00
// Credentials holds SMTP endpoint and authentication methods
type Credentials struct {
2017-08-02 15:26:31 +01:00
SMTPuserid string
SMTPpassword string
SMTPhost string
SMTPport string
SMTPsender string
2016-07-07 18:54:16 -07:00
}
2017-08-02 15:26:31 +01:00
// GetAuth to return SMTP authentication details
func (m *Mailer) GetAuth() smtp.Auth {
2017-08-04 13:17:09 +01:00
a := smtp.PlainAuth("", m.Credentials.SMTPuserid, m.Credentials.SMTPpassword, m.Credentials.SMTPhost)
2016-07-07 18:54:16 -07:00
return a
}
2016-07-25 14:03:11 -07:00
// GetHost to return SMTP host details
2017-08-02 15:26:31 +01:00
func (m *Mailer) GetHost() string {
2017-08-04 13:17:09 +01:00
h := m.Credentials.SMTPhost + ":" + m.Credentials.SMTPport
2016-07-07 18:54:16 -07:00
return h
}
2017-08-02 15:26:31 +01:00
2017-08-04 13:17:09 +01:00
// LoadCredentials loads up SMTP details from database
func (m *Mailer) LoadCredentials() {
2017-08-27 16:39:09 +01:00
userID, _ := m.Store.Setting.Get("SMTP", "userid")
m.Credentials.SMTPuserid = strings.TrimSpace(userID)
pwd, _ := m.Store.Setting.Get("SMTP", "password")
m.Credentials.SMTPpassword = strings.TrimSpace(pwd)
host, _ := m.Store.Setting.Get("SMTP", "host")
m.Credentials.SMTPhost = strings.TrimSpace(host)
port, _ := m.Store.Setting.Get("SMTP", "port")
m.Credentials.SMTPport = strings.TrimSpace(port)
sender, _ := m.Store.Setting.Get("SMTP", "sender")
m.Credentials.SMTPsender = strings.TrimSpace(sender)
2017-08-02 15:26:31 +01:00
}