Newer
Older
zangtumb / handler.go
Loweel on 17 Aug 641 bytes First Release
package main

import (
	"bytes"
	"log"
	"net"
)

func mailHandler(origin net.Addr, from string, to []string, data []byte) {
	SmtpSession := new(Session)

	log.Printf("Received mail from %s for %q from %s", from, to, origin.String())
	log.Println(" Recipients: ", to)

	for _, rcptTo := range to {
		SmtpSession.Reset()

		if rcptErr := SmtpSession.Rcpt(rcptTo); rcptErr == nil {
			SmtpSession.MailFrom = from
			if dataErr := SmtpSession.Data(bytes.NewReader(data)); dataErr != nil {
				log.Println("Problem Saving Message: ", dataErr.Error())
			}
			log.Println("Session is: ", SmtpSession)
		} else {
			log.Println(rcptErr)
		}

	}

}