Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How does mailutils "mail" command or cron contact local MTA?

23 views
Skip to first unread message

Yvan Masson

unread,
Sep 17, 2022, 5:20:07 PM9/17/22
to
Hi,

I have some servers successfully configured to send notification emails,
but I do not exactly understand how it works :-)

I have installed openSMTPd and configured it to forward email to a relay
(another SMTP server, the one from my email provider). I have also set
up aliases in `/etc/aliases`. This allows me to send email from my
servers, either when cron runs a task, or when I run `echo my_content |
mail -s subject root` from scripts.

My question is: how cron daemon and mail command know that they should
contact openSMTPd, and how? Do they try by default on localhost:25 or
/run/smtpd.sock? I could not find any clue, nor in cron manpages nor in
mailutils online documentation.

Regards,
Yvan
OpenPGP_signature

Greg Wooledge

unread,
Sep 17, 2022, 6:40:06 PM9/17/22
to
On Sat, Sep 17, 2022 at 11:11:51PM +0200, Yvan Masson wrote:
> My question is: how cron daemon and mail command know that they should
> contact openSMTPd, and how? Do they try by default on localhost:25 or
> /run/smtpd.sock? I could not find any clue, nor in cron manpages nor in
> mailutils online documentation.

mail(1) or mailx(1) or similar utilities run the /usr/sbin/sendmail
program to inject a new message into the local MTA.

/usr/sbin/sendmail was of course originally provided by the sendmail
package. But later MTAs implement a /usr/sbin/sendmail compatible wrapper
so that all the utilities that send mail don't have to change.

Yvan Masson

unread,
Sep 18, 2022, 3:30:06 AM9/18/22
to
Thanks Greg!

Indeed, just to confirm for other interested on this topic, this is
documented for `mail` command on
https://mailutils.org/manual/mailutils.html#Mail-Variables, and for
Vixie/ISC cron (default cron daemon on Debian) on
https://salsa.debian.org/debian/cron/-/blob/master/config.h.

So the `mailutils` package with `mail` command is optional: `sendmail`
could be used directly in scripts (but it might be a bit less practical
to use, see for example
https://www.computerhope.com/unix/usendmai.htm#examples).

Regards,
Yvan
OpenPGP_signature

Greg Wooledge

unread,
Sep 18, 2022, 9:10:06 AM9/18/22
to
On Sun, Sep 18, 2022 at 09:27:46AM +0200, Yvan Masson wrote:
> So the `mailutils` package with `mail` command is optional: `sendmail` could
> be used directly in scripts (but it might be a bit less practical to use,
> see for example https://www.computerhope.com/unix/usendmai.htm#examples).

If you call /usr/sbin/sendmail, you have to write all of the headers
yourself, with correct (or at least acceptably close) syntax.

The only time a shell script should be calling /usr/sbin/sendmail directly
is when you're trying to do something that your MUA (mailx, et al.) doesn't
allow, such as forging a bogus Date: header, or overriding the envelope
sender address.

In normal usage, scripts should always be calling mailx or an equivalent
program which is *designed* to create the e-mail headers correctly. This
is especially true if you're sending attachments. Writing the MIME headers
and attachment markup yourself is not going to be fun.

Teemu Likonen

unread,
Sep 19, 2022, 1:10:06 AM9/19/22
to
* 2022-09-18 09:00:49-0400, Greg Wooledge wrote:

> In normal usage, scripts should always be calling mailx or an
> equivalent program which is *designed* to create the e-mail headers
> correctly. This is especially true if you're sending attachments.
> Writing the MIME headers and attachment markup yourself is not going
> to be fun.

Mailx, or even better, Mutt:

mutt [-nx] [-e command] [-F rcfile] [-b bcc-addr] [-c cc-addr]
[-s subject] [-a file ... --] to-addr ... < message

--
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 6965F03973F0D4CA22B9410F0F2CAE0E07608462
signature.asc
0 new messages