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

3

1

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 ?

Pooja25

Posted 2014-02-06T08:41:53.807

Reputation: 33

You can use PGP on the commandline: http://www.symantec.com/command-line

– SPRBRN – 2014-02-06T08:53:23.850

Encrypt how...? – Adrian Frühwirth – 2014-02-06T09:03:07.143

can you please provide me the format for that? whether should I use pgp or gpg ? – Pooja25 – 2014-02-06T09:13:41.190

Answers

4

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:

#!/bin/bash
date > /tmp/gpgtxt.txt


gpg -ea -r receiver@mail.com /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://smtp.gmail.com:587 \
-S from="sender@send.com" \
-S smtp-auth-user=sender@send.com \
-S smtp-auth-password="senderpassword" \
receiver@mail.com

jst

Posted 2014-02-06T08:41:53.807

Reputation: 41

0

cat "your message" > msg # just type your message. You can use editor too. 
gpg -ear "reciever gpg key" msg # encrypt it.
cat msg.asc | mail -s "subject" "reciever mail address" # Hit enter. 

Syfi Malik

Posted 2014-02-06T08:41:53.807

Reputation: 11

cat takes a files as an argument, not a string. So unless you have a file called your\ message, this will give you a "No such file or directory" error... – Stefan van den Akker – 2019-08-13T19:19:36.637