13 type ReplyLine struct {
18 func (l ReplyLine) String() string {
19 return fmt.Sprintf("%d %s", l.Code, l.Message)
22 const SendAsAddress = "sendas+"
25 ReplyOK = ReplyLine{250, "OK"}
26 ReplyBadSyntax = ReplyLine{501, "syntax error"}
27 ReplyBadSequence = ReplyLine{503, "bad sequence of commands"}
28 ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
29 ReplyMailboxUnallowed = ReplyLine{553, "mailbox name not allowed"}
32 func DomainForAddress(addr mail.Address) string {
33 return DomainForAddressString(addr.Address)
36 func DomainForAddressString(address string) string {
37 domainIdx := strings.LastIndex(address, "@")
41 return address[domainIdx+1:]
44 type Envelope struct {
54 func WriteEnvelopeForDelivery(w io.Writer, e Envelope) {
55 fmt.Fprintf(w, "Delivered-To: <%s>\r\n", e.RcptTo[0].Address)
56 fmt.Fprintf(w, "Return-Path: <%s>\r\n", e.MailFrom.Address)
60 type Server interface {
62 TLSConfig() *tls.Config
63 VerifyAddress(mail.Address) ReplyLine
64 // Verify that the authc+passwd identity can send mail as authz.
65 Authenticate(authz, authc, passwd string) bool
66 OnMessageDelivered(Envelope) *ReplyLine
68 // RelayMessage instructs the server to send the Envelope to another
69 // MTA for outbound delivery.
70 RelayMessage(Envelope)
73 type EmptyServerCallbacks struct{}
75 func (*EmptyServerCallbacks) TLSConfig() *tls.Config {
79 func (*EmptyServerCallbacks) VerifyAddress(mail.Address) ReplyLine {
83 func (*EmptyServerCallbacks) Authenticate(authz, authc, passwd string) bool {
87 func (*EmptyServerCallbacks) OnMessageDelivered(Envelope) *ReplyLine {
91 func (*EmptyServerCallbacks) RelayMessage(Envelope) {