Configure mail sending
|Configure mail sending|
Organic Design procedure
Mail sending is complicated, it requires that the sending server have valid reverse DNS, DKIM signature, SPF and DMARC records. If you just need basic sending capability, then it's much simpler and lighter weight to use an external mail sending service, so we can simply connect to their SMTP server to send mail.
To make this setup as transparent and light-weight as possible, we use the MSMTP simple sendmail alternative. That way all applications on the server can send email using the local sendmail utility as expected, but the actual job of sending is delegated to the remote SMTP server.
apt install msmtp
Make sure that Exim4 is not installed (use dpkg -l to see what's installed), and that /usr/bin/sendmail points to msmtp, so that default system mail mechanisms will work properly.
dpkg -l | grep exim apt remove exim4-daemon-light ln -s /usr/bin/msmtp /usr/sbin/sendmail
Msmtp configuration is /etc/msmtprc, a basic configuration to simply forward every by default to a remote SMTP server is as follows:
account default syslog LOG_MAIL maildomain organicdesign.co.nz host smtp.organicdesign.co.nz auto_from on port 587 tls on tls_starttls on auth plain user YOUR_USER_NAME password YOUR_UNIX_PASSWORD
There will likely be no program installed for the mail command to work, so if you need this then a very basic Perl script can be installed in /usr/local/bin/mail as follows:
#!/usr/bin/perl my $input = join( '', <STDIN> ); qx( echo "Subject: $ARGV\n\n$input" | msmtp $ARGV );
Note: This is extremely basic and only allows the absolute simplest use of the mail command, where the body is sent to STDIN and a subject is supplied with the -s option followed by the recipient email address.
Then test sending a message to yourself using all standard methods that are expected to work:
echo "testing" | mail -s "mail test" email@example.com echo "Subject: sendmail test" | sendmail -v "firstname.lastname@example.org" echo '<?php mail("email@example.com","php test","testing");' | php