How to send attachment with unix mail command
To send an attachment with the mail
command in Unix, you can use the -a
option followed by the name of the attachment file. Here's an example:
mail -s "Subject" [email protected] -a attachment.txt
This will send an email with the subject "Subject" to [email protected]
and attach the file attachment.txt
.
If you want to send multiple attachments, you can use the -a
option multiple times:
mail -s "Subject" [email protected] -a attachment1.txt -a attachment2.txt
This will send an email with the subject "Subject" to [email protected]
and attach both attachment1.txt
and attachment2.txt
.
You can also use the -A
option to specify the attachment file name and content type:
mail -s "Subject" [email protected] -A "attachment.txt;type=text/plain"
This will send an email with the subject "Subject" to [email protected]
and attach the file attachment.txt
with a content type of text/plain
.
Note that the mail
command may not work with all email clients or servers, and the attachment may not be delivered correctly. It's always a good idea to test the attachment with a different email client or server to ensure it works correctly.
Also, you can use uuencode
command to encode the attachment before sending it:
uuencode attachment.txt attachment.txt | mail -s "Subject" [email protected]
This will encode the attachment.txt
file and send it as an attachment.
You can also use mutt
command which is a more powerful email client that allows you to send attachments:
mutt -s "Subject" [email protected] < attachment.txt
This will send an email with the subject "Subject" to [email protected]
and attach the file attachment.txt
.