wo-bisch-lorahandler/mail.go

47 lines
993 B
Go

package main
import (
"log"
"net/smtp"
)
func sendEmail(mail_to, mail_default_authuser, mail_message string) {
var auth smtp.Auth
if getenv("MAILSERVER_USER", "") != "" {
// Set up authentication information.
auth = smtp.PlainAuth(
"",
getenv("MAILSERVER_USER", ""),
getenv("MAILSERVER_PASSWORD", ""),
getenv("MAILSERVER_HOST", "127.0.0.1"),
)
}
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
err := smtp.SendMail(
getenv("MAILSERVER_HOST", "127.0.0.1")+":"+getenv("MAILSERVER_PORT", "25"),
auth,
getenv("MAILSERVER_USER", mail_default_authuser),
[]string{mail_to},
[]byte(mail_message),
)
if err != nil {
log.Fatal(err)
}
}
func sendEmailMessage(username, message string) {
mail_message := "To: " + username + `
From: info@wo-bisch.ch
Subject: ` + message + `
Lieber Benutzer von wo-bisch.ch
` + message + `
--
wo-bisch.ch`
sendEmail(username, "mail@wo-bisch.ch", mail_message)
}