Sunday, January 17, 2010

Mailing from command line in UNIX



      There are lot of instances when we want to send a mail to our outlook or personal account from the UNIX account.  Say, could be to send a mail with a subject alone, mail with contents or mail with attachment.  The mail with attachment is one of the most used forms among the three because many a time we would need to do something with a UNIX file in windows. So, instead of FTPing which takes some time, we can easily mail the file being from the UNIX account.

   The following section shows how to send mails from the UNIX box (HP and SUN)

HP:

1. Mail with body:
    #mailx -m -s "report" gpr@xyz.com < usage_report

      where usage_report is the file containing the body to be mailed, and "report" is the subject of the mail and gpr@xyz.com is the mail-id of the user to whom the mail is to be sent.

2. Mail with attachment:
    #ux2dos usage_report | uuencode usage_report  | mailx -m -s "report" gpr@xyz.com

      where usage_report is the file to be sent as attachment.



SunOs:

1. Mail with body:
    #mailx  -s "report" gpr@xyz.com < usage_report

      where usage_report is the file containing the body to be mailed, and "report" is the subject of the mail and gpr@xyz.com is the mail-id of the user to whom the mail is to be sent.

2. Mail with attachment:
    #unix2dos usage_report | uuencode usage_report  | mailx  -s "report" gpr@xyz.com

      where usage_report is the file to be sent as attachment.




No comments:

Post a Comment