Debug email class (even though no used)
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmailAccount struct {
|
type EmailAccount struct {
|
||||||
@@ -20,6 +22,7 @@ type EmailAccountData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createEmailAccount(accountData EmailAccountData, smtpHost string, smtpPort int) EmailAccount {
|
func createEmailAccount(accountData EmailAccountData, smtpHost string, smtpPort int) EmailAccount {
|
||||||
|
logging.Debugf("Creating Email Account: \nUsername: %s\nEmail: %s\nSMTP Host: %s:%d", accountData.username, accountData.email, smtpHost, smtpPort)
|
||||||
account := EmailAccount{
|
account := EmailAccount{
|
||||||
email: accountData.email,
|
email: accountData.email,
|
||||||
smtpHost: smtpHost,
|
smtpHost: smtpHost,
|
||||||
@@ -30,13 +33,9 @@ func createEmailAccount(accountData EmailAccountData, smtpHost string, smtpPort
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendEmail(account EmailAccount, toEmail []string, subject string, message string) {
|
func sendEmail(account EmailAccount, toEmail []string, subject string, message string) {
|
||||||
ToEmailList := ""
|
logging.Debugf("Sending an email from %s to %s", account.email, strings.Join(toEmail, ""))
|
||||||
for i := 0; i < len(toEmail); i++ {
|
|
||||||
ToEmailList += toEmail[i]
|
ToEmailList := strings.Join(toEmail, "")
|
||||||
if i+1 < len(toEmail) {
|
|
||||||
ToEmailList += ", "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
messageData := []byte(
|
messageData := []byte(
|
||||||
"From: " + account.email + "\r\n" +
|
"From: " + account.email + "\r\n" +
|
||||||
@@ -47,6 +46,7 @@ func sendEmail(account EmailAccount, toEmail []string, subject string, message s
|
|||||||
)
|
)
|
||||||
err := smtp.SendMail(account.smtpHost+":"+account.smtpPort, account.auth, account.email, toEmail, messageData)
|
err := smtp.SendMail(account.smtpHost+":"+account.smtpPort, account.auth, account.email, toEmail, messageData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
logging.Error("Failed to send email")
|
||||||
|
logging.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user