Monday, February 20, 2012

mail command with specific recipient

Mail command can be used to send email from any UNIX or Linux system to other system. Basically they are command based email program to send email.

mail -s "Subject" name@example.com

To send the email with particular sender email ID then use the below syntax.

mail -s "Subject" name@example.com -- -r "user1@example.com"

Why it becomes very particular to send with an email ID because when you use a mail program it assumes that the logged in user as the sender from the base(current  working) machine. These type of emails are generally rejected on the basis of doubt for spam.

So i recommend a particular email ID for sender which will ensure the safe journey of email.

Body with file redirection:

To send email with data from a file or a source you can always redirect the information to the mail command.

 mail -s "Subject for test" name@example.com -- -r "user1@example.com" </etc/mail/sendmail.cf

The email from user1@example.com to name@example.com will have a subject as 'Subject for test' and carry the data from the sendmail.cf file.

No comments:

Post a Comment