You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Josef Fröhle 88a3f1f3a5 „gomilter.go“ ändern 2 years ago
.gitignore Update README and fix sample filter 6 years ago
LICENSE Initial commit 6 years ago Update README and fix sample filter 6 years ago
filter.c Fix license 6 years ago
filter.h Fix license 6 years ago
gomilter.go „gomilter.go“ ändern 2 years ago
samplefilter.go Update README and fix sample filter 6 years ago
samplefilter2.go go fmt 5 years ago


Go Bindings for Sendmail's libmilter

Tested on Linux and FreeBSD


The Sendmail header file libmilter/mfapi.h is required. For Redhat/CentOS, install the sendmail-devel package:

yum install sendmail-devel

Install the gomilter package:

go get


The milter is implemented in a struct. Start by defining your own struct type and embeding the gomilter MilterRaw struct.

type Mymilter struct {
	gomilter.MilterRaw // Embed the basic functionality.

Milter callbacks are added by implementing methods for the struct with matching predefined names.


  • Connect
  • Helo
  • EnvFrom
  • EnvRcpt
  • Header
  • Eoh
  • Body
  • Eom
  • Abort
  • Close

Not all the callbacks need to be defined. The callbacks are explained on the site. Unfortunately the site has been shut down but it is still on

Message Modification Functions

  • AddHeader
  • ChgHeader
  • InsHeader
  • ChgFrom
  • AddRcpt
  • AddRcpt_Par
  • DelRcpt
  • ReplaceBody

Other Message Handling Functions

  • progress


The Socket field of the milter struct must be set. For example:

mymilter.Socket = "unix:/var/gomilter/socket"

Control is handed over to the libmilter smfi_main function by calling the Run method and passing it a pointer to your milter struct


The milter has a Stop method which calls the libmilter smfi_stop function.

Private Data

libmilter is able to store private data for a connection. This data can be accessed from other functions and callbacks for the same connection. You can pass a pointer to any data structure to SetPriv. The data is retrieved with GetPriv

t := T{1, 2, 3}
m.SetPriv(ctx, &t)

Retrieve the data with

var t T
m.GetPriv(ctx, &t))

GetPriv should only be called once. If the private data is needed in another function or callback then call SetPriv again.

Sample Programs

There are two sample programs included, samplefilter.go and samplefilter2.go

##Other Libraries

A usefull MIME parsing library is go.enmime