What do you use as a lightweight SMTP for outgoing e-mails only?

I am running an app that sends e-mails via SMTP when events occur once in a while, and I don't need a fully featured e-mail server.

EDIT: I am more than happy to use something like postfix (and do), if that's the best choice. I was thinking there may be something much simpler, that runs out the box.

  • I think it is perfectly reasonable to stick with something like exim and postfix. They aren't hard to configure if you are doing simple things. Commented May 7, 2013 at 19:16
  • What's your definition of "lightweight"? How large are you expecting the messages to be? How often is "once in a while"?
    – Mike B
    Commented Feb 6, 2015 at 19:45
  • The emailrelay.sourceforge.net is exactly for this. It also works on Windows. Commented Sep 29, 2022 at 17:07

8 Answers 8


There are several choices of minimal, relay-only mail transfer agents (MTAs, or "mail servers"), some of which have been mentioned in other answers:

For either of those to work, you need a full fledged MTA somewhere that will further relay your messages (known as "mail hub") and it is strongly recommended that you control this mail hub. Bad Things™ can happen otherwise.

  • esmtp is no longer being maintained. Commented Aug 6, 2013 at 7:56
  • 2
    nullmailer has a serious SMTP compliance problem : it retries infinitely when given an SMTP permanent error. This can cost you real money if you pay for bandwidth/transit bugs.debian.org/cgi-bin/bugreport.cgi?bug=329192
    – not an ai
    Commented Feb 6, 2014 at 16:13
  • @telent: you should not use nullmailer in such a scenario.
    – user601
    Commented Feb 7, 2014 at 12:09
  • Thanks! The config guide at troubleshooters.com/linux/nullmailer notes a security issue with nullmailer: it exposes passwords on the command line, or at least used to do that. Other conversations note that mstmp makes it a bit less clear how to enqueue mail than nullmailer.
    – nealmcb
    Commented Jun 12, 2019 at 3:35

IMHO, the easiest way to do this is with postfix. You can configure it as a light outgoing relay with these commands:

postconf -e relayhost=other.mailserver.com
postconf -e myorigin=my.domainname.com

As long as the SMTP server specified in relayhost doesn't require authentication, allows you to relay or is a valid destination for the recipient address this will work.

The myorigin parameter will be the default domain name. So if you send mail to foo it will go to [email protected]. Mail sent by user bar will be from [email protected].

If you do need to authenticate and want to support TLS, also run the following commands:

postconf -e smtp_tls_security_level=may
postconf -e smtp_sasl_auth_enable=yes
postconf -e smtp_sasl_password_maps=pcre:/etc/postfix/sasl_password_maps

Then in /etc/postfix/sasl_password_maps have this content:

/./ username:password

All mail will be sent to your relayhost with the specified username and password.

  • Tried these settings and I get an error: "error: unsupported dictionary type: pcre"
    – valentt
    Commented Nov 6, 2015 at 11:37
  • 1
    Install pcre and/or postfix-pcre and try again.
    – bahamat
    Commented Nov 7, 2015 at 6:48
  • I figured it out, also in the mean time, there were two packages missing, first one is postfix-pcre as you said, but other one was a strange one - libsasl2-modules. I'm puzzled how libsasl2 and libsasl2-modules-db were installed but libsasl2-modules was missing... Now finally everything works. Can you please add this crucial info to your answer?
    – valentt
    Commented Nov 9, 2015 at 11:39
  • 1
    For tls, I also used: relayhost=other.mailserver.com:465 then smtp_tls_wrappermode=yes and smtp_tls_security_level=encrypt but it's attempting to use the local user as the auth. I have to rewrite the auth user somehow. Commented Jun 29, 2016 at 4:13
  • "As long as the SMTP server specified in relayhost doesn't require authentication" -> ok, but that's rarely the case nowadays. Your suggestion is correct, but mostly irrelevant!
    – FarO
    Commented Jun 12, 2019 at 9:16

Assuming you need a program you can run from the shell like sendmail(8), perhaps MSMTP will fit your needs? It can connect to a remote SMTP server and submit mail it gets as stdin, just like sendmail.

  • I use MSMTP for this, works great and the configuration is very simple.
    – dsp
    Commented Sep 1, 2010 at 15:16
  • I'm so glad you recommended this. I've been looking for something like that for quite a while now. sendmail's configuration is just way too differentiated for my needs.
    – ixtmixilix
    Commented Sep 3, 2010 at 20:33

ESMTP is a relay only mail transfer server that may work for your application.

  • 1
    project seems dead as of 2009
    – SHernandez
    Commented Jul 4, 2015 at 15:08

You may find sSMTP suitable for your needs. Read this article on it and its limitations.

Honestly though, I wouldn't be too stressed about installing postfix or exim, even if it is only for sending emails.

  • 1
    +1 for ssmtp, -1 for the unnecessary comment at sendmail, as well as recommending using a full mta, which is way harder to do right. badly configured and maintained mail servers make the life of us mail admins hell.
    – user601
    Commented Sep 1, 2010 at 11:27
  • @hop: I disagree on both counts. sendmail is awful. Also, exim for example is the Debian default, and is perfectly simple to use. So is postfix, probably, but I have never used it. Commented May 7, 2013 at 19:14

If you use docker, https://hub.docker.com/r/zixia/simple-mail-forwarder/ is a good choice for easy deploy and only of 10MB size, with full smtp(tls) support.


You technically don't need an e-mail server on your host, what you need (and probably already have) is an smtp-client (or MUA) that can connect to your corporate SMTP Server (which could be anywhere you can connect to.)

Depending on the App (and the programming language it was written in) there are many different ways for your app to connect to the 'the' SMTP Server on your network.

Usually, with PHP or Python, there's a configuration file with the app to specify the "SMTP" Server (which can be on your host or elsewhere on your network.) If you already have a mail server on the network, then just point the configuration to that server.

If no other options exist, the app can generate the e-mail message to standard output that you can process with something like:

listoftargets="[email protected] [email protected]" echo "Test Content" | mail -s "Test Subject" $listoftargets

On some systems, there is already a minimal mailserver for sending only.

Sam T.

  • I have a whole bunch of servers in the cloud, and I really wanted each to have their own outgoing SMTP servers, rather than rely on anything external. In that way, if my remote SMTP server is down, it's not effecting every server. Commented Sep 1, 2010 at 10:09
  • 1) if you let PHP or Python do the smtp part, you have to do all the work (queueing, error handling) that an MTA would handle. 2) at the end you contradict what you say in the beginning
    – user601
    Commented Sep 1, 2010 at 11:16
  • Some linux applications are setup to expect mail or sendmail named executables. System notifications. That's the whole point isn't it? For anything else there are no constraints. Commented Jul 14, 2018 at 22:20

apt install postfix (will also restart config if installed)
Edit this config file: vi /etc/postfix/main.cf

Uncomment this line or use this sed:
sed -i 's/#smtp_sasl_security_options/smtp_sasl_security_options/' /etc/postfix/main.cf

Add your smtp info and reload service:
echo '[smtp.gmail.com]:587 <your_email>:<your_password>' > /etc/postfix/sasl_passwd && chmod 600 /etc/postfix/sasl_passwd (or [smtp.sendgrid.net]:587 apikey:xxx)
postmap /etc/postfix/sasl_passwd && systemctl reload postfix

Test it:
mail $EMAIL <<< "message" works.. or also(sendmail -f $EMAIL $EMAIL <<< "message")

Weekly postive control test message:
echo "mail -s "email test on: $(hostname)" root \<\<\< "email_test" > /etc/cron.weekly/email_test or if using .env/file:
echo "mail -s "email test on: $(hostname)" \$(cat ~/.env/EMAIL)" \<\<\< "email_test" > /etc/cron.weekly/email_test

To use one email forwarding for all root mail:
echo "your_email_address" >> /etc/aliases && newaliases and test with:
echo "body" | mail -s "subject" root

Now all apps mailing to root will go to your email. More info here:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .