Newer
Older
zangtumb / zangtumb.go
package main

import (
	"log"
	"os"

	"zangtumb/smtpd"
)

var ZangSmtpServer *smtpd.Server
var KeyFile, CrtFile, ServerName, ListenAddr string

const AppName = "ZangTumb"

func init() {

	ZangSmtpServer = new(smtpd.Server)

	KeyFile = os.Getenv("KEYFILE")
	log.Println("KeyFile: ", KeyFile)
	CrtFile = os.Getenv("CERTFILE")
	log.Println("CrtFile: ", CrtFile)
	ServerName = os.Getenv("DOMAINNAME")
	log.Println("ServerName: ", ServerName)
	ListenAddr = os.Getenv("LISTEN")
	log.Println("ListenAddr: ", ListenAddr)

	ZangSmtpServer.AuthRequired = false
	ZangSmtpServer.Hostname = ServerName
	ZangSmtpServer.MaxRcpt = SmtpBackend.MaxRecipients
	if ZangSmtpServer.MaxRcpt == 0 {
		ZangSmtpServer.MaxRcpt = 1
		log.Println("No recipients, setting MaxRcpt to 1")
	} else {
		log.Println("MaxRcpt: ", ZangSmtpServer.MaxRcpt)
	}

	if os.Getenv("USETLS") == "true" {

		ZangSmtpServer.ConfigureTLS(CrtFile, KeyFile)
		ZangSmtpServer.TLSListener = false
		ZangSmtpServer.TLSRequired = true
		log.Println("Using TLS")

	} else {

		ZangSmtpServer.TLSListener = false
		ZangSmtpServer.TLSRequired = false
		log.Println("WARNING: NOT Using TLS")
	}

}

func main() {

	if err := smtpd.ListenAndServe(ListenAddr, mailHandler, AppName, ServerName, ZangSmtpServer); err != nil {
		log.Panicln("Ops. Something went wrong: ", err.Error())
	}

}