Fossil User Forum

Can’t make fossil to send emails
Login

Can’t make fossil to send emails

Can't make fossil to send emails

(1) By drvolodya on 2024-10-27 16:57:17 [link] [source]

Hi, any help would be appreciated in finding out why fossil can't send emails.

Saving emails to a file and then doing sendmail -ti <file runs fine and sends out that email, but using pipe to sendmail -ti in fossil does nothing, but the alert queue is empty, the messages seem go somewhere.

Ubuntu, self-hosted fossil.

./fossil set email-send-command -R repo
output:
email-send-command (local) sendmail -ti

Thank you!

(2) By Stephan Beal (stephan) on 2024-10-27 18:24:38 in reply to 1 [source]

Hi, any help would be appreciated in finding out why fossil can't send emails.

i've never set it up to send directly to sendmail, but the following approach (derived from one Richard passed on to me long ago) works great for me and might work for you:

  • Under /setup_notification, use the "Store in a database" option.
  • Set the db path, e.g. mine's /jail/notifications/repos.db1.
  • Make sure that dir is writable by the account which runs the web server/fossil.
  • But before all of that...

Create a TCL script (or equivalent) which looks something like:

#!/usr/bin/tclsh

set POLLING_INTERVAL 60000   ;
set DBFILE /jail/notifications/repos.db
set PIPE "/usr/sbin/sendmail -t"

package require sqlite3
sqlite3 db $DBFILE
db timeout 5000
catch {db eval {PRAGMA journal_mode=WAL}}
db eval {
  CREATE TABLE IF NOT EXISTS email(
    emailid INTEGER PRIMARY KEY,
    msg TXT
  );
}
# Close and re-open the db on each attempt, rather than hold it
# constantly open, because experience shows that with the latter
# approach the notifications all pile up in the WAL file and never
# land in the db.
db close
while {1} {
  sqlite3 db $DBFILE
  db transaction immediate {
    set n 0
    db eval {SELECT msg FROM email} {
      set pipe $PIPE
      if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all addr]} {
        append pipe " -f $addr"
      }
      set out [open |$pipe w]
      puts -nonewline $out $msg
      flush $out
      close $out
      incr n
    }
    if {$n>0} {
      db eval {DELETE FROM email}
    }
  }
  db close
  after $POLLING_INTERVAL
}

Then the obligatory workaround script:

#!/bin/sh
# Workaround to start send-fossil-notifications.tcl without
# my local LD_LIBRARY_PATH's copy of libsqlite3 getting in the
# way. It also ensures that the notifications aren't running more
# than once at a time.
LD_LIBRARY_PATH=
export LD_LIBRARY_PATH
pid=`pgrep -f send-fossil-notifications.tcl`
# If pgrep isn't available (e.g. in busybox):
# pid=`ps -ef | grep send-fossil-notifications.tcl | grep -v grep | awk '{print $1}'`
# ^^^^ noting that in busybox the PID is field $1 and in /bin/ps it's $2!
if test x != "x$pid"; then
    kill -9 $pid
fi
exec nohup /jail/bin/send-fossil-notifications.tcl >/dev/null 1>&2 &

Then a cronjob to send out the notifications:

$ crontab -l | grep notif
@reboot sleep 60 && /jail/bin/send-fossil-notifications.sh &>/dev/null

Sidebar: some people will say "crontab!?!?! Nooooo! Use systemd!" To which i say "systemd!?!?! Nooooo!" because "if it ain't broke, don't fix it."


  1. ^ The /jail dir is my chroot chain, but that dir contains a symlink named jail which points to . so that the above scripts can use the path /jail/... regardless of whether they're running inside the jail or not.

(3) By drvolodya on 2024-10-27 20:29:57 in reply to 2 [link] [source]

Thank you Stephan,
once I knew saving messages to files worked, I made a simple shell script to send them out. It's similar to what you are doing, but I call periodically from cron rather than having a loop.
I'd still be interested having fossil send emails directly.
Cheers

#!/bin/bash
EMAIL_DIR=fossil_emails/
for entry in "$EMAIL_DIR"*.email
do
  /usr/sbin/sendmail -ti <"$entry"
  rm "$entry"
done

(4) By Richard Hipp (drh) on 2024-10-28 09:49:13 in reply to 3 [link] [source]

When this Forum sends email, it writes the email into a database. Then a separate process sees that new messages have been added to the database and sends those messages and removes them.

The emails pass through a database this way because this Forum is running inside a chroot jail that does not have access to the programs or shared libraries necessary for sending email on its own. Is your Fossil instance running inside a chroot jail too? Could that be the problem?

(5) By Warren Young (wyoung) on 2024-10-28 15:28:05 in reply to 1 [link] [source]

The sendmail binary is in /usr/sbin on Ubuntu. Is that in the PATH used by your background fossil instance? Have you tried giving the full path name instead of relying on the PATH?

I did have this working on Ubuntu at one point, so yes, it can work. I switched to the email DB method that Stephan and drh are talking about when I containerized my server; it can't call sendmail directly for the same reason you can't do it from a chrooted binary.