• Stars
    star
    313
  • Rank 129,329 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Golang SMTP server

tmail

Join the chat at https://gitter.im/toorop/tmail

tmail is a SMTP server

Features

  • SMTP, SMTP over SSL, ESMTP (SIZE, AUTH PLAIN, STARTTLS)
  • Advanced routing for outgoing mails (failover and round robin on routes, route by recipient, sender, authuser... )
  • SMTPAUTH (plain & cram-md5) for in/outgoing mails
  • STARTTLS/SSL for in/outgoing connexions.
  • Manageable via CLI or REST API.
  • DKIM support for signing outgoing mails.
  • Builtin support of clamav (open-source antivirus scanner).
  • Builtin Dovecot (imap server) support.
  • Fully extendable via plugins
  • Easy to deploy
  • No dependencies: -> you do not have to install nor maintain libs
  • Clusterisable (todo)
  • IPV6 (soon)

Quick install on linux (Ubuntu)

For french users see: http://tmail.io/doc/installer-tmail/

add user tmail

adduser tmail

Fetch tmail dist

# su tmail
$ cd
$ wget ftp://ftp.toorop.fr/softs/tmail/tmail.zip
$ unzip tmail.zip
$ cd dist

Under dist you will find:

  • conf: configuration.
  • run: script used to launch tmail
  • ssl: is the place to store SSL cert. For testing purpose you can use those included.
  • tmail: tmail binary
  • tpl: text templates.
  • db: if you use sqlite as DB backend (MySQL and Postgresql are also supported), sqlite file will be stored in this directory.
  • store: mainly used to store raw email when they are in queue. (others kind of backend/storage engine are coming)
  • mailboxes: where mailboxes are stored if you activate Dovecot support.

Make run script and tmail runnable:

chmod 700 run tmail

add directories:

mkdir db
mkdir store

if you want to enable Dovecot support add mailboxes directory:

mkdir mailboxes

See Enabling Dovecot support for tmail (french) for more info.

Configuration

Init you conf file:

cd conf
cp tmail.cfg.base tmail.cfg
chmod 600 tmail.cfg
  • TMAIL_ME: Hostname of the SMTP server (will be used for HELO|EHLO)

  • TMAIL_DB_DRIVER: I recommend sqlite3 unless you want to enable clustering (or you have a lot of domains/mailboxes)

  • TMAIL_SMTPD_DSNS: listening IP(s), port(s) and SSL options (see conf file for more info)

  • TMAIL_DELIVERD_LOCAL_IPS: IP(s) to use for sending mail to remote host.

  • TMAIL_SMTPD_CONCURRENCY_INCOMING: max concurent incomming proccess

  • TMAIL_DELIVERD_MAX_IN_FLIGHT: concurrent delivery proccess

Init database

tmail@dev:~/dist$ ./run
Database 'driver: sqlite3, source: /home/tmail/dist/db/tmail.db' misses some tables.
Should i create them ? (y/n): y

[dev.tmail.io - 127.0.0.1] 2015/02/02 12:42:32.449597 INFO - smtpd 151.80.115.83:2525 launched.
[dev.tmail.io - 127.0.0.1] 2015/02/02 12:42:32.449931 INFO - smtpd 151.80.115.83:5877 launched.
[dev.tmail.io - 127.0.0.1] 2015/02/02 12:42:32.450011 INFO - smtpd 151.80.115.83:4655 SSL launched.
[dev.tmail.io - 127.0.0.1] 2015/02/02 12:42:32.499728 INFO - deliverd launched

Port forwarding

As you run tmail under tmail user, it can't open port under 1024 (and for now tmail can be launched as root, open port under 25 and fork itself to unprivilegied user).

The workaround is to use iptables to forward ports. For example, if we have tmail listening on ports 2525, and 5877 and we want tu use 25 and 587 as public ports, we have to use those iptables rules:

iptables -t nat -A PREROUTING -p tcp --dport 25 -j REDIRECT --to-port 2525
iptables -t nat -A PREROUTING -p tcp --dport 587 -j REDIRECT --to-port 5877

First test

$ telnet dev.tmail.io 25
Trying 151.80.115.83...
Connected to dev.tmail.io.
Escape character is '^]'.
220 tmail.io  tmail ESMTP f22815e0988b8766b6fe69cbc73fb0d965754f60
HELO toto
250 tmail.io
MAIL FROM: [email protected]
250 ok
RCPT TO: [email protected]
554 5.7.1 <[email protected]>: Relay access denied.
Connection closed by foreign host.

Perfect ! You got "Relay access denied" because by default noboby can use tmail for relaying mails.

Relaying mails for @example.com

If you want tmail to relay mails for example.com, just run:

tmail rcpthost add example.com

Note: If you have activated Dovecot support and example.com is a local domain, add -l flag :

tmail rcpthost add -l example.com

Does it work as expected ?

$ telnet dev.tmail.io 25
Trying 151.80.115.83...
Connected to dev.tmail.io.
Escape character is '^]'.
220 tmail.io  tmail ESMTP 96b78ef8f850253cc956820a874e8ce40773bfb7
HELO toto
250 tmail.io
mail from: [email protected]
250 ok
rcpt to: [email protected]
250 ok
data
354 End data with <CR><LF>.<CR><LF>
subject: test tmail

blabla
.
250 2.0.0 Ok: queued 2736698d73c044fd7f1994e76814d737c702a25e
quit
221 2.0.0 Bye
Connection closed by foreign host.

Yes ;)

Allow relay from an IP

tmail relayip add IP

For example:

tmail relayip add 127.0.0.1

Basic routing

By default tmail will use MX records for routing mails, but you can "manualy" configure alternative routing. If you want tmail to route mail from @example.com to mx.slowmail.com. It is as easy as adding this routing rule

tmail routes add -d example.com -rh mx.slowmail.com

You can find more elaborated routing rules on tmail routing documentation (french) (translators are welcomed ;))

SMTP AUTH

If you want to enable relaying after SMTP AUTH for user [email protected], just enter:

tmail user add -r [email protected] password

If you want to delete user [email protected] :

tmail user del [email protected]

Let's Encrypt (TLS/SSL)

If you want to activate TLS/SSL connections with a valid certificate (not an auto-signed one as it's by default) between mail clients and your tmail server you can get a let's Encrypt certificate, you have first to install let's Encrypt :

cd ~
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt

Then you can request a certificate

./letsencrypt-auto certonly --standalone -d your.hostname

You'll have to provide a valid mail address and agree to the Let's Encrypt Term of Service. When certificate is issued you have to copy some files to the ssl/ directory

cd /home/tmail/dist/ssl
cp /etc/letsencrypt/live/your.hostname/fullchain.pem server.crt
cp /etc/letsencrypt/live/your.hostname/privkey.pem server.key
chown tmail.tmail server.*

And it's done !

Contribute

Feel free to inspect & improve tmail code, PR are welcomed ;)

If you are not a coder, you can contribute too:

  • install and use tmail, I need feebacks.

  • as you can see reading this page, english is not my native language, so I need help to write english documentation.

Roadmap

  • clustering
  • IPV6
  • write unit tests (yes i know...)
  • improve, refactor, optimize
  • test test test test

License

MIT, see LICENSE

Imported packages

github.com/nsqio/nsq/... github.com/codegangsta/cli github.com/codegangsta/negroni github.com/go-sql-driver/mysql github.com/jinzhu/gorm github.com/julienschmidt/httprouter github.com/kless/osutil/user/crypt/... github.com/lib/pq github.com/mattn/go-sqlite3 github.com/nbio/httpcontext golang.org/x/crypto/bcrypt golang.org/x/crypto/blowfish

More Repositories

1

go-bittrex

Go binding for the Bittrex crypto-currency exchange API.
Go
230
star
2

gin-logrus

gin middleware for logrus
Go
104
star
3

go-dkim

DKIM package for golang
Go
94
star
4

go-bitcoind

A Golang client library wrapping the bitcoind JSON RPC API
Go
80
star
5

ovh-cli

Command-line tool to consume OVH services
Go
71
star
6

ovh-sdk-php

OVH SDK for PHP
PHP
55
star
7

banisher

The Banisher watches your systemd journal and bans, with no delay, abusers.
Go
32
star
8

go-pusher

A golang pusher client
Go
29
star
9

HubicSwiftGateway

HubicSwiftGateway allows you to create an openStack Swift Gateway to Hubic storage
PHP
24
star
10

Phubic

PHP class to interact with Hubic Cloud Storage
PHP
20
star
11

OVHBilling

PHP script to download your OVH bills
13
star
12

runabove-cli

Command-line tool to interact with Runabove services
Go
10
star
13

gox

Painless MySQL backup (and restore)
Go
9
star
14

reganam

JavaScript
9
star
15

go-qonto

Go API client and CLI for https://qonto.eu/ banking service.
Go
8
star
16

khao

khao is a cookie switcher which have the aim of creating chaos in tracker databases
JavaScript
7
star
17

pure

HTTP proxy
Go
6
star
18

AutoTrackIR

AutoTrackIR will automatically re-enabled your Track IR if flight simulator disabled it. (bug introduce in SU7)
Go
5
star
19

govh

Golang Package to interact with OVH API
Go
4
star
20

tmail-dashboard

A web interface to manage your tmail server or cluster
Go
4
star
21

mysql-backup

A set of tool to backup, archive and restore MySql, MariaDB, Percona database
Shell
4
star
22

logrusOVH

OVH logs PAAS Hook for Logrus
Go
3
star
23

btsync-daemontools-script

daemontool script to supervise (watch & relaunch if needed) btsync daemon
3
star
24

netqmail

Raw netqmail
C
3
star
25

podkstr

A set of tools for podcasters
Go
3
star
26

form2mail

Send your form to your form2mail URL and it will be forwarded to your email. (formspree clone)
Go
2
star
27

online-cli

Online.net command line interface
Go
2
star
28

gopentsdb

Golang OpenTSDB Client
Go
2
star
29

KonKr-anti-spam-plugin-for-wordpress

A anti-spam plugin for Wordpress using the free KonKr API
PHP
2
star
30

Grunt-PHPUnit-demo

Source for Grunt & PHPUnit tutorial
PHP
2
star
31

cors-proxy

Golang reverse proxy which adds CORS headers to the proxied request.
Go
2
star
32

ProtecmailOutlookAddIn

Protecmail Addin for outlook 2013 - 2016 (work in progress)
C#
2
star
33

qmail-boosters

qmail-booster is a set of qmail binaries replacement which add functionalities to qmail
Go
2
star
34

FsBlackBox

Flight recorder for Flight Simulator 2020
2
star
35

tuto-time-series-ovh

Vous trouverez ici le code source utilisé dans le tutoriel sur le PAAS time series OVH
Go
2
star
36

flightradar

Golang SDK to fetch data from flight trackers as flightradar24
Go
2
star
37

logalert

Log and alert package for Go
Go
1
star
38

pepper

Because black boxes suck
Go
1
star
39

autotube.support

Use this repo to report bugs or to propose new feature for AutoTube
1
star
40

otp-demo

HTML
1
star
41

go-coinbase

A Go package to consume Coinbase API.
Go
1
star
42

daemontools-go-logger

Simple logger package for go services supervised by DJB deamontools
Go
1
star
43

scaleway-availability

Golang package and CLI tool to check availability of scaleaway instances
Go
1
star
44

goabove

Go package to interact with Runabove
Go
1
star
45

autotu.be

https://autotu.be website
Vue
1
star
46

pushover

pushover client library for golang (forked from github.com/thorduri/pushover)
Go
1
star
47

kinsta

Instagram API
Go
1
star
48

calc

Initiation aux modules Golang
Go
1
star
49

gotchat

A Golang chat package
Go
1
star
50

ovhlogger

pipe STDIN to OVH Logs Data Platform
Go
1
star
51

toorop.fr

https://toorop.fr
HTML
1
star
52

podstats

Collect stats about your podcasts
Go
1
star
53

tmail-ms-server

Microservices server for tmail (POC)
Go
1
star