go-smtpsrv

a tiny package that implements SMTP server for Go projects

Github星跟踪图

A SMTP Server Package

a simple smtp server library, forked from This repo but I refactored it to be more advanced and organized

Features

  • Very simple
  • Automated SPF Checks
  • Automated FROM validation (MX checking), via Request.Mailable
  • Supports TLS
  • Modular, as you can add more smtp command processors to extend the functionality as you need

Quick Start

go get github.com/alash3al/go-smtpsrv

package main

import (
	"fmt"

	"github.com/alash3al/go-smtpsrv"
)

func main() {
	handler := func(req *smtpsrv.Request) error {
		// ...
		return nil
	}
	srv := &smtpsrv.Server{
		Name: "mail.my.server",
		Addr:        ":25025",
		MaxBodySize: 5 * 1024,
		Handler:     handler,
	}
	fmt.Println(srv.ListenAndServe())
}

Security

The smtp server also supports the STARTTLS option, if you use the ListenAndServeTLS variant.
You can also further customize the tls config as well.

server := smtp.Server{Name: "example.com", Debug: true}
config := &tls.Config{MinVersion:tls.VersionSSL30}
server.TLSConfig = config
log.Fatal(server.ListenAndServeTLS(":smtp", "cert.pem", "key.pem", nil))

Authentication

The smtp server also supports authentication via the PLAIN method. Ideally this would be
coupled with STARTTLS to ensure secrecy of passwords in transit. You can do this by creating
a custom server and registering the AUTH callback. This will be called everytime someone
attempts to authenticate.

server.Auth = func(username, password, remoteAddress string) error {
	if username == "user" && password == "p@$$w0rd" {
		return nil
	}
	return errors.New("Nope!")
}

Addressing and preventing open-relay

Since your callback is only called once the smtp protocol has progressed to the data point,
meaning the sender and recipient have been specified, the server also offers an Addressable
callback that can be used to deny unknown recipients.

server.Addressable = func(user, address string) bool {
	if user != ""{
		//Allow relay for authenticated users
		return true
	}
	if strings.HasSuffix(address, "example.com"){
		return true
	}
	return false
}

主要指标

概览
名称与所有者alash3al/go-smtpsrv
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2018-10-23 13:29:18
推送于2023-12-10 07:01:18
最后一次提交2022-09-14 22:27:10
发布数4
最新版本名称v3.0.1 (发布于 )
第一版名称v1.0 (发布于 )
用户参与
星数105
关注者数2
派生数30
提交数49
已启用问题?
问题数7
打开的问题数3
拉请求数7
打开的拉请求数2
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?