0

I'm looking to send emails to myself from various scripts on my Linux (Debian 10) system. My thought was to install just Dovecot, and not an MTA like Postfix, to avoid the complexity of configuring the MTA. All I want to do is drop myself the odd email from a script, and then connect to my mail server with Thunderbird and pull those emails.

I used to run my own email server, however, and the way I sent scripts on there was to use /usr/sbin/sendmail. This binary seems to have been supplied by Postfix, because it isn't there with just a Dovecot install.

Assuming I have already set up Dovecot to successfully allow retrieval of email from local user mailboxes via eg. POP3, what's the simplest way (least configuration, basically) for me to send email to those local mailboxes from a unix script? I'd like to avoid installing a full-on MTA, or ideally, anything else at all. I'd like some sort of equivalent to:

/usr/sbin/sendmail "[email protected]" <<EOF_emailContent
(email here)
EOF_emailContent
Jez
  • 948
  • 3
  • 15
  • 33
  • What is your OS? The setup of an MTA for local delivery only should not be too difficult. – Bodo Jan 20 '22 at 12:10
  • Linux (Debian 10). – Jez Jan 20 '22 at 13:29
  • I suggest to install an MTA, e.g. `exim4`. IIRC it has a menu-based configuration where it should be easy to select a configuration for local delivery. – Bodo Jan 20 '22 at 13:57

1 Answers1

2

The basic problem is that without an MTA, these mailboxes have no email address. They are nothing but some files on disk. Dovecot doesn't need to understand email addresses.

The usual arrangement between an MTA (like postfix) and Dovecot is that both the MTA and Dovecot are configured to expect the same layout of either mbox files or maildir directories. But the mapping is very different for the MTA vs Dovecot.

  • Dovecot understands which users read / write which mailboxes
  • The MTA understands which email addresses get routed to which mail boxes.

You might assume that an email sent to [email protected] would go to user bob; that only happens because the MTA knows to route [email protected] into bob's mailbox /home/bob/.mail. Then when bob logs in via IMAP or POP3, Dovecot know that bob's mailbox is /home/bob/.mail.

...But the MTA might also route emails for [email protected] to bob's mailbox too. It may even route [email protected] into /home/mary/.mail when bob quits the company and his successor receives his email. It's entirely the job of the MTA to decide.

So without an MTA of some sort, you cannot route email into inboxes.


There are simpler MTAs. Postfix is rather awkward to configure and nobody wants the risk of accidentally misconfiguring an MTA and letting spammers abuse it.

I'll draw your attention to another question here on U&L which is similar (not duplicate?). Minimal MTA that delivers mail locally (for cron)?


If you are willing to roll your own, then the formats of both maildir and mbox are pretty simple. Though maildir is much safer to work with. Delivering to maildir is as simple as writing to the tmp directory and then moving (renaming) it into the new directory.

Of course these have to be well formatted emails with appropriate headers such as From: To: Subject: Date:. Examples can be found in RFC 5322

Philip Couling
  • 17,591
  • 5
  • 42
  • 82
  • I don't really need to route email addresses though. As I said I'm just sending some emails to myself locally so my script could just specify "send to bob's mailbox". – Jez Jan 20 '22 at 16:44
  • @Jez yes that's why I linked [that answer](https://unix.stackexchange.com/a/82367/20140). The point of this answer is to highlight that this functionality is outside of Dovecot's remit and any MTA (even femto) is build on the concept of sending to an email address. If you are using maildir (not mbox) then delivering mail to the mailbox is as trivial as writing the email as a file into the `new` directory. Remember to add email headers such as `From:`, `To:` and `Subject:` etc. – Philip Couling Jan 20 '22 at 16:49