In This post we will see how to send email using mailx command available in most of the Unix like operating system.
SYNTAX: mailx <Switch> "<Subject>" <Email Of Address Recipient>
Email With subject
mailx -s "Test" "A1@kw.com"
Output: Will send an email to A1@kw.com with subject line as test
To: A1@kw.com
Email With CC and BCC
We can also use cc and bcc email option by using -c and -b
mailx -s "test" -c "A2@kw.com" -b "A3@kw.com" "A1@kw.com"
Output: Email recipients will appear as shown below in email.
To: A1@kw.com
Cc: A2@kw.com
Bcc: A3@kw.com
Email With body
We can do that in multiple ways:
echo "Hello User" | mailx -s "test" "A1@kw.com"
Output:In this case, email body will have following text: "Hello User"
We can also use the content of a file as an email body, for example we have a file F_Msg_File.txt
cat F_Msg_File.txt
Hi User,
Please Note, We will be discussing mailx command.
Thanks
Knowledge Warehouse
(cat F_Msg_File.txt) | mailx -s "test" "A1@kw.com"
[OR]
mailx -s "test" "A1@kw.com" < F_Msg_File.txt
Output: Above command will send an email to the user with the file content as email body.
Email With Attachment
We can attach(log file or anything) an attachment in the email by using uuencode command.
(uuencode F_Log_File.txt F_Log_File.txt) | mailx -s "test" "A1@kw.com"
Email With Attachment & body
(cat F_Msg_File.txt; uuencode F_Error_File.txt F_Error_File.txt) | mailx -s "test" A1@kw.com
Output: Will attach F_Error_File.txt in email as attachment and display the content of F_Msg_File.txt as email body.
Note: Observe carefully, we have provided F_Log_File.txt wice in uuencode command.
Keep Reading, Keep Learning, Keep Sharing...!!
No comments:
Post a Comment