Migrate Email Sending from sendmail to SMTP#
This guide explains how to migrate server-side scripts from the old sendmail-based email
setup (caosadvancedtools.serverside.helper.send_mail) to pylinkahead’s native SMTP-based
send_email. After the migration, LinkAhead no longer needs access to a sendmail binary
or a local mail relay on the host.
Prerequisites#
You have identified all server-side scripts that currently call
helper.send_mail(...).You have the credentials and hostname for your institution’s SMTP server, or have decided on an external relay. See Configure Email for Server-Side Scripts.
Steps#
Configure the new
[Email]section incaosdb-server/scripting/home/pylinkahead.inias described in Configure Email for Server-Side Scripts.If your old setup used an external relayhost (configured via
relayhostincustom/other/main.cf), you can pointsmtp_serverdirectly at that host with no TLS or credentials – no Postfix intermediary is needed:[Email] smtp_server=relay.host.example.com smtp_port=25 from_address=LinkAhead <linkahead@example.com>
Update each server-side script that calls
helper.send_mail. Replace it withsend_emailfrom pylinkahead:Old:
from caosadvancedtools.serverside import helper helper.send_mail(from_addr="linkahead@example.com", to=recipient, subject=subject, body=message, cc=cc, bcc=bcc)
New:
from linkahead.utils.email import send_email send_email(message=message, to=recipient, from_address="linkahead@example.com", subject=subject, cc=cc, bcc=bcc)
The key differences:
bodyis renamed tomessageand becomes the first positional argument.from_addris renamed tofrom_address. If you setfrom_addressin the[Email]section ofpylinkahead.ini, you can omit it from each call entirely.subject,cc, andbccremain unchanged but are now keyword arguments.send_mail_binhas no equivalent and should be dropped.
Developers can use the test email setup to verify their changes locally before deploying.
Remove the old configuration:
In
caosdb-server/scripting/home/pylinkahead.ini, remove thesendmailentry from the[Misc]section:[Misc] sendmail=/usr/sbin/sendmail # remove this line
If you had a relayhost setup and
custom/other/main.cfis not used for anything else, delete it.
In your
profile.yml, setmailtofalseand remove thesendmailentry (or leave it – it is ignored whenmailisfalse):mail: false # sendmail: /usr/sbin/sendmail # no longer needed
If the local mail relay (e.g. Postfix) was running solely to support this setup and is not used for anything else, you can now decommission it.