2024-06-29 Sending mail from the laptop to the server via NNCP

This is a continuation of 2024-06-28 Connecting the laptop to the server via NNCP, based on the UUCP setup described in 2024-06-15 Old tech: UUCP, and @jgoerzen@floss.social's Asynchronous Email: Exim over NNCP (or UUCP).

2024-06-28 Connecting the laptop to the server via NNCP

2024-06-15 Old tech: UUCP

Asynchronous Email: Exim over NNCP (or UUCP)

Debian is using Exim 4. This laptop is not always connected to the internet. Let's do some configuring! I'll keep some of my mistakes in here because I know when I'm having trouble I'm always running into mistakes. Running into and recovering from mistakes is more important than just the instructions.

First, I need to make sure that `mail` doesn't send mail using `msmtp` anymore.

~/.mailrc

This used to say:

set sendmail="/usr/bin/msmtp"

This will have to go, for the moment. Otherwise, mail sent using `mail` is going to be sent via `msmtp`.

/etc/exim4/update-exim4.conf.conf

This is the file generated by `dpkg-reconfigure exim4-config` and then used by `update-exim4.conf` to write the real config file in `/var/lib/exim4/config.autogenerated`.

This is the content of the file. `melanobombus` is the name of my laptop. In the rest of this blog post I'm going to assume that exim uses a split config.

dc_eximconfig_configtype='local'
dc_other_hostnames='melanobombus'
dc_local_interfaces='127.0.0.1 ; ::1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='true'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

/etc/exim4/conf.d/router/110_exim4-config_nncp

A new router for NNCP mail that has to come before `200_exim4-config_primary`. If it comes after the primary, then it won't work because the primary router ends with `no_more` and as the comment at the end of the file says:

The `no_more` above means that all later routers are for domains in the local_domains list

This router only accepts mail destined for domains listed in the new file `/etc/exim4/nncp`.

nncp_router:
    debug_print = "R: nncp_router for $local_part@$domain"
    driver=accept
    require_files = +/usr/bin/nncp-exec
    domains = wildlsearch;/etc/exim4/nncp
    transport = nncp

/etc/exim4/nncp

This is a file that translates the domain names I use for recipients to NNCP names.

Mail sent to `alex@campaignwiki.org` from the laptop is delivered to `sibirocobombus` via NNCP:

campaignwiki.org	sibirocobombus

`sibirocobombus` is correct because `/etc/nncp.hjson` has a section for `neigh.sibirocobombus` as discussed in 2024-06-28 Connecting the laptop to the server via NNCP. Note that I use `neigh.sibirocobombus.exec.rsmtp`. If you use `neigh.sibirocobombus.exec.sendmail` as mentioned on that other blogpost, you'll get an error that I'll discuss down below when I'm testing the setup. 😅

2024-06-28 Connecting the laptop to the server via NNCP

    sibirocobombus: {
      id:       CCAIPFSAZWYICBQ5BIURX4UMEJIXVSZFIING7HRUFTDOFV5XISVQ
      exchpub:  NGEIDPDVZ2I6CTRKCBT734VV4W2YFVTV6YFBU5UGB6IHBA3QDJUQ
      signpub:  VXBMWXS74IGAYQCLJY4UPAXXQXPT3K53QI5XCFHOAKL4I2FQNLKQ
      noisepub: MGGBAOHRHEWEC6CGT47GA2DOQXQFZUAKJ66PD734Y5WNWP364UXQ
      incoming: "/home/alex/incoming/sibirocobombus"
      exec: {
       rsmtp: ["/usr/sbin/sendmail", "-bS"]
      }
      addrs: {
        internet: "alexschroeder.ch:5400"
      }
      calls: [
        {
          cron: "12 * * * *"
        }
      ]
    }

/etc/exim/conf.d/transport/40_exim4-config_nncp

The route above says that the transport to use is `nncp`.

Define this using a new transport config file:

nncp:
    debug_print = "T: nncp for $pipe_addresses"
    driver=pipe
    user=nncp
    command = /usr/bin/nncp-exec -noprogress -quiet $domain_data rsmtp
    use_bsmtp
    return_fail_output

Testing it

As an ordinary user, use `mail` on the command line to send mail to `alex@campaignwiki.org`.

mail alex@campaignwiki.org
Subject: test
hallo
.
Cc:

As `root`, check the exim log:

tail /var/log/exim4/mainlog

Here's a failure:

2024-06-29 09:42:14 1sNSis-000En9-17 <= alex@alexschroeder.ch U=alex P=local S=469
2024-06-29 09:42:14 1sNSis-000En9-17 ** alex@campaignwiki.org R=nonlocal: Mailing to remote domains not supported
2024-06-29 09:42:14 1sNSis-000EnD-1E <= <> R=1sNSis-000En9-17 U=Debian-exim P=local S=1791
2024-06-29 09:42:14 1sNSis-000En9-17 Completed
2024-06-29 09:42:14 1sNSis-000EnD-1E ** alex@alexschroeder.ch R=nonlocal: Mailing to remote domains not supported
2024-06-29 09:42:14 1sNSis-000EnD-1E Frozen (delivery error message)

To delete frozen messages (until this setup works):

exiqgrep -z | awk -e '/frozen/ {print $3}' | xargs exim -Mrm

What's the problem? Searching the config files for the error message yields a hit in `/etc/exim4/conf.d/router/200_exim4-config_primary`:

.ifdef DCconfig_local
# configtype=local
#
# Stand-alone system, so generate an error for mail to a non-local domain
nonlocal:
  debug_print = "R: nonlocal for $local_part@$domain"
  driver = redirect
  domains = ! +local_domains
  allow_fail
  data = :fail: Mailing to remote domains not supported
  no_more

.endif

This should work since the NNCP router is defined in `/etc/exim4/conf.d/router/110_exim4-config_nncp`. The problem is that all this small files need to be reassembled into the actual config file.

Regenerate the exim4 config files:

sudo update-exim4.conf

Here's another failure:

2024-06-29 12:30:48 1sNVM0-000H2v-1t <= alex@melanobobmus U=alex P=local S=461
2024-06-29 12:30:48 1sNVM0-000H2v-1t ** alex@campaignwiki.org R=nncp_router T=nncp: Child process of nncp transport returned 1 from command: /usr/bin/nncp-exec
2024-06-29 12:30:48 1sNVM0-00004v-2G <= <> R=1sNVM0-000H2v-1t U=Debian-exim P=local S=1931
2024-06-29 12:30:48 1sNVM0-000H2v-1t Completed
2024-06-29 12:30:48 1sNVM0-00004v-2G ** alex@melanobobmus R=nonlocal: Mailing to remote domains not supported
2024-06-29 12:30:48 1sNVM0-00004v-2G Frozen (delivery error message)

Delete the frozen email. 🙁

What happened here is that NNCP router succeeded and picked the `nncp` transport which called `nncp-exec` but that failed – and so the mail was passed the `nonlocal` router that results in the same error message as noted in the previous failure.

In my case, the problem was that the transport I had still contained `user=uucp` instead of `user=nncp`. Hopefully you're not running into the same problem. But if you are, here's your pointer to check the split config files again.

Remember to run `update-exim4.conf` so that the change makes it into the real config file.

This is what success looks like:

tail /var/log/exim4/mainlog
2024-06-29 12:39:25 1sNVUL-0000Iz-0U <= alex@melanobobmus U=alex P=local S=461
2024-06-29 12:39:25 1sNVUL-0000Iz-0U => alex <alex@campaignwiki.org> R=nncp_router T=nncp
2024-06-29 12:39:25 1sNVUL-0000Iz-0U Completed

The NNCP log file looks good:

nncp-log
2024-06-29T10:39:25Z Exec is sent to sibirocobombus@rsmtp (614 B)

Make the call:

sudo -u nncp nncp-call sibirocobombus
2024-06-29T10:41:42Z We have got for sibirocobombus: 1 packets, 818 B
2024-06-29T10:41:42Z Connection to sibirocobombus (alexschroeder.ch:5400)
2024-06-29T10:41:42Z Tx OECV4I7DKMIKY4RB..DPFM74TTNUIMQ5NQ 818 B/818 B 100% (0 B/sec)
2024-06-29T10:41:42Z Packet OECV4I7DKMIKY4RB34PW5WP5JVZODF6SSGMMDPFM74TTNUIMQ5NQ is sent
2024-06-29T10:41:53Z Finished call with sibirocobombus (0:0:11): 32 KiB received (32 KiB/sec), 33 KiB transferred (33 KiB/sec)

Switch over to the server:

nncp-stat
melanobombus
	nice:   P | Rx:      818 B,   1 pkts | Tx:        0 B,   0 pkts
self

The packet has arrived!

Let's process it:

sudo -u nncp nncp-toss
2024-06-29T10:43:11Z ERROR Tossing exec melanobombus/OECV4I7DKMIKY4RB34PW5WP5JVZODF6SSGMMDPFM74TTNUIMQ5NQ (338 B): rsmtp: No handle found

Oh no!

The reason is that when I set up the `/etc/nncp.hjson` on the server (see 2024-06-28 Connecting the laptop to the server via NNCP), I had specified:

2024-06-28 Connecting the laptop to the server via NNCP

      exec: {
        sendmail: ["/usr/sbin/sendmail"]
      }

Let's change that to `rsmtp`.

     exec: {
       rsmtp: ["/usr/sbin/sendmail", "-bS"]
     }

Try again.

sudo -u nncp nncp-toss
2024-06-29T12:52:45Z Got exec from melanobombus to rsmtp (338 B)

Yay!

Check the mail?

mail
Mail version 8.1.2 01/15/2001.  Type ? for help.
"/var/mail/alex": 1 message 1 unread
>U  1 alex@melanobobmus  Sat Jun 29 14:52   26/821   test
& 1
Message 1:
From alex@melanobobmus Sat Jun 29 14:52:45 2024
Envelope-to: alex@campaignwiki.org
Delivery-date: Sat, 29 Jun 2024 14:52:45 +0200
To: alex@campaignwiki.org
Subject: test
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
From: Alex Schroeder <alex@melanobobmus>
Date: Sat, 29 Jun 2024 12:39:25 +0200

hallo

& d
& q

Ohhh, so nice!

Now I just need to figure out how this works for the way back.

Sending mail from the server back to the laptop via NNCP

Let's do this! We know all the parts.

Create `/etc/exim4/conf.d/router/111_exim4-config_nncp` as follows:

nncp_router:
    debug_print = "R: nncp_router for $local_part@$domain"
    driver = accept
    require_files = +/usr/bin/nncp-exec
    domains = wildlsearch;/etc/exim4/nncp
    transport = nncp

Create `/etc/exim4/nncp` as follows:

melanobombus    melanobombus

Create `/etc/exim4/conf.d/transport/41_exim4-config_uucp` as follows:

nncp:
    debug_print = "T: nncp for $pipe_addresses"
    driver=pipe
    user=nncp
    command = /usr/bin/nncp-exec -noprogress -quiet $domain_data rsmtp
    use_bsmtp
    return_fail_output

Make sure to change `neigh.sibirocobombus.exec` as follows on the laptop (with `sibirocobombus` being the name of the server):

     exec: {
       rsmtp: ["/usr/sbin/sendmail", "-bS"]
     }

Let's give this a try!

On the server:

mail alex@melanobombus
Subject: test
ok
.
Cc: 

Check the Exim log:

tail /var/log/exim4/mainlog
2024-06-29 17:33:07 1sNa4Z-001HeA-1v <= alex@alexschroeder.ch U=alex P=local S=442
2024-06-29 17:33:07 1sNa4Z-001HeA-1v ** alex@melanobombus: Unrouteable address
2024-06-29 17:33:07 1sNa4Z-001HeD-25 <= <> R=1sNa4Z-001HeA-1v U=Debian-exim P=local S=1700
2024-06-29 17:33:07 1sNa4Z-001HeA-1v Completed
2024-06-29 17:33:07 1sNa4Z-001HeD-25 => alex <alex@alexschroeder.ch> R=local_user T=mail_spool
2024-06-29 17:33:07 1sNa4Z-001HeD-25 Completed

Oops, I forgot to regenerate the real Exim config file!

update-exim4.conf

Write another mail, check the Exim log again. As you can see, I wrote this one from my root account. And it worked!

2024-06-29 17:35:19 1sNa6h-001I0a-0E <= root@alexschroeder.ch U=root P=local S=432
2024-06-29 17:35:19 1sNa6h-001I0a-0E => alex <alex@melanobombus> R=nncp_router T=nncp
2024-06-29 17:35:19 1sNa6h-001I0a-0E Completed

Check the NNCP log:

nncp-log | tail
2024-06-29T15:35:19Z Exec is sent to melanobombus@rsmtp (596 B)

Now remember that the server doesn't call the laptop. So do this, but from the laptop!

sudo -u nncp nncp-call sibirocobombus
2024-06-29T15:37:28Z Packet 362MNMYNNHK57E4OMFP5OTZPSAMIYHFKZHSUJZFVPJID76PYJ45Q (800 B) (nice P): 0%
2024-06-29T15:37:28Z sibirocobombus has got for us: 1 packets, 800 B
2024-06-29T15:37:28Z Connection to sibirocobombus (alexschroeder.ch:5400)
2024-06-29T15:37:28Z Rx 362MNMYNNHK57E4O..JZFVPJID76PYJ45Q 800 B/800 B 100% (0 B/sec)
2024-06-29T15:37:28Z Got packet 362MNMYNNHK57E4OMFP5OTZPSAMIYHFKZHSUJZFVPJID76PYJ45Q 100% (800 B / 800 B): done
2024-06-29T15:37:39Z Finished call with sibirocobombus (0:0:11): 33 KiB received (33 KiB/sec), 32 KiB transferred (32 KiB/sec)

Check stats:

alex@melanobombus ~> sudo -u nncp nncp-stat
sibirocobombus
	nice:   P | Rx:      800 B,   1 pkts | Tx:        0 B,   0 pkts

Process ("toss") the packet:

sudo -u nncp nncp-toss
2024-06-29T15:39:00Z Got exec from sibirocobombus to rsmtp (320 B)

Check mail:

mail
Mail version 8.1.2 01/15/2001.  Type ? for help.
"/var/mail/alex": 1 message 1 new
>N  1 root@alexschroede  Sat Jun 29 17:39   25/794   test
& 1
Message 1:
From root@alexschroeder.ch Sat Jun 29 17:39:00 2024
Envelope-to: alex@melanobombus
Delivery-date: Sat, 29 Jun 2024 17:39:00 +0200
To: alex@melanobombus
Subject: test
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
From: root <root@alexschroeder.ch>
Date: Sat, 29 Jun 2024 17:35:19 +0200

ok

& d
& q

Exim decided to use "alexschroeder.ch" as the domain and not "sibirocobombus". Hm. I guess in those cases where I know the mail is going to be sent by NNCP I should change that.

​#Administration ​#NNCP