commento/api/smtp_domain_export_error.go

29 lines
781 B
Go
Raw Normal View History

2019-01-31 15:06:11 +08:00
package main
import (
"bytes"
"net/smtp"
"os"
)
type domainExportErrorPlugs struct {
2019-02-05 07:10:59 +08:00
Origin string
2019-01-31 15:06:11 +08:00
Domain string
}
func smtpDomainExportError(to string, toName string, domain string) error {
var header bytes.Buffer
headerTemplate.Execute(&header, &headerPlugs{FromAddress: os.Getenv("SMTP_FROM_ADDRESS"), ToAddress: to, ToName: toName, Subject: "Commento Data Export"})
var body bytes.Buffer
templates["data-export-error"].Execute(&body, &domainExportPlugs{Origin: os.Getenv("ORIGIN")})
err := smtp.SendMail(os.Getenv("SMTP_HOST")+":"+os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body))
if err != nil {
logger.Errorf("cannot send data export error email: %v", err)
return errorCannotSendEmail
}
return nil
}