Linux – How to send encrypted mail using mailx command in Linux/Unix


I want to make my email encrypted as email is confidential. Can anyone please tell me how to encrypt the email using the mailx command. In my shell script I have already used mailx to send the emails, so I want this to be done by mailx command only. Any suggestions ?

Best Answer

Here’s how I did it:

  1. Create text file.
  2. Encrypt that text file.
  3. Attach that encrypted text file to an email.

Here is a Bash script that implements the idea:

date > /tmp/gpgtxt.txt

gpg -ea -r /tmp/gpgtxt.txt

cat /tmp/gpgtxt.txt.asc | mailx -s "cli encryption" \
-a /tmp/gpgtxt.txt.asc \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp:// \
-S from="" \
-S \
-S smtp-auth-password="senderpassword" \