Sometimes as an Administrator meet conditions need sending an email via CLI, for example to send backup status, notification of server conditions and others. As a Zimbra Mail Administrator, we need send email with command line use zimbra engine for sending. Overwrite sendmail that used transport by default.
In fact even though we have already installed zimbra and running well, and when want to send email from the command line, the mail engine transport not use zimbra. By default using sendmail and the path already exists. Therefore, in this article we will modify the sendmail/mta path so that it can use the zimbra engine as Mail Transport.
Install Mailx for send email command zimbra
For this purpose we can use the mailx
application which can be installed with the following command:
yum install mailx
As describe above, by default the mail command will use the sendmail
CLI to send email. So we must change or modify that the mail
command uses the zimbra engine. Here is command that run in zimbra 8.8.12.
rm /etc/alternatives/mta
rm /usr/sbin/sendmail
rm /usr/lib/sendmail
ln -s /opt/zimbra/common/sbin/sendmail /etc/alternatives/mta
ln -s /etc/alternatives/mta /usr/sbin/sendmail
ln -s /etc/alternatives/mta /usr/lib/sendmail
Note: for zimbra version 8.60 earlier, please replace :
/opt/zimbra/common/sbin/sendmail
to
/opt/zimbra/postfix/sbin/sendmail
Test Send Email via CLI
Then test running the mail command:
mail -a /tmp/verbose.txt -s 'Test Email mydomain.com at' $ DATE '' [email protected]
-a
: Add attachment parameter, followed path of file that will be attach.-s
: Subject of mail that will be send.[email protected]
: receiver of mail.
The above command will send an email with the subject “Test Email mydomain.com at (date current)” to email [email protected] with the contents of the e-mail taken from the file /tmp/verbose.txt.
Cheers.