Sending and email in UNIX- Bells & Whistles
Here is an example of how you can send an email with Subject, To, CC, bcc, etc.
It will follow the format:
cat filename ¦ mailx -s subject -r senders_mail_id -b bcc_list_mail_id -c cc_list to_mail_id
cat filename : this will print the contents of the file called filename on standard output.
¦ : The pipe would pass the standard output to the mailx command.
mailx : This is the magic word. The mailx command.
-s : Specify the subject of the email following -s
subject : A text field (can be surrounded by double quotes if contains space) to be sent as subject of the email.
-r : denotes the return path (Sender's email address)
-b : a list of email ids in the bcc field (put in quotes if multiple, separated by commas)
-c : a list of email ids in the cc field
to_mail_id : The email id that is to appear in the "To" field of the email.
an example:
cat chagansmail.txt ¦ mailx -s "This is a test email - ($datestamp2)" -r myaddress@yahoo.com -b abc@hotmail.com -c "def@gmail.com,hatter@mail.com,mad@earthlink.net" greatman@aol.com
As you can see, you can include variables in the fields, too.
It will follow the format:
cat filename ¦ mailx -s subject -r senders_mail_id -b bcc_list_mail_id -c cc_list to_mail_id
cat filename : this will print the contents of the file called filename on standard output.
¦ : The pipe would pass the standard output to the mailx command.
mailx : This is the magic word. The mailx command.
-s : Specify the subject of the email following -s
subject : A text field (can be surrounded by double quotes if contains space) to be sent as subject of the email.
-r : denotes the return path (Sender's email address)
-b : a list of email ids in the bcc field (put in quotes if multiple, separated by commas)
-c : a list of email ids in the cc field
to_mail_id : The email id that is to appear in the "To" field of the email.
an example:
cat chagansmail.txt ¦ mailx -s "This is a test email - ($datestamp2)" -r myaddress@yahoo.com -b abc@hotmail.com -c "def@gmail.com,hatter@mail.com,mad@earthlink.net" greatman@aol.com
As you can see, you can include variables in the fields, too.

0 Comments:
Post a Comment
<< Home