A go SMTP library pieced together from other libraries. Provides support for mail attachments

Caerostris a0d4d2d363 update git server url 3 years ago
LICENSE f79a2c2de6 added readme and license 4 years ago
README.md a0d4d2d363 update git server url 3 years ago
mailBodyParser.go f79a2c2de6 added readme and license 4 years ago
mailHeaderParser.go f79a2c2de6 added readme and license 4 years ago
server.go c6d98109ad added plain and html bodies to MailItem 4 years ago



smtp is a simple smtp server library for golang
It is based on the server component of GoGuerilla and the mail parser of MailSlurper.
In contrast to most other server libraries, this one supports attachments.


The usage is similiar to net/http:

smtp.ListenAndServe(interface string, hostname string, receiveMail smtp.HandlerFunc)

where interface is a string like :25 or, hostname is the server's identification string and receiveMail is the function that is called for incoming emails.
The function receiveMail is passed a smtp.MailItem and returns an error which is used to indicate successfull processing to the SMTP client

This example should cover everything:

package main

import (

func receiveMail(mailItem *smtp.MailItem) error {
    log.Printf("Received mail: %s", mailItem.Body)

    return nil

func main() {
    err := smtp.ListenAndServe(":"+strconv.Itoa(port), "dutchman.vfl.pw", receiveMail)
    if err != nil {

Relevant structures:

type MailItem struct {
    DateSent    string
    FromAddress string
    ToAddress   string
    Subject     string
    XMailer     string
    Body        string
    ContentType string
    Boundary    string
    Attachments []*Attachment

type Attachment struct {
    Headers  *AttachmentHeader
    Contents string

type AttachmentHeader struct {
    ContentType             string
    Boundary                string
    MIMEVersion             string
    ContentTransferEncoding string
    ContentDisposition      string
    FileName                string
    Body                    string


  • Add SSL/TLS support
  • Support multiple recipients


Both GoGuerilla and MailSlurper are relaesed under the MIT license.