How to attach a file in mail command
To attach a file to an email using the mail
command, you can use the -a
or --attach
option followed by the name of the file you want to attach.
Here is an example:
mail -s "Subject" -a file.txt [email protected]
This will attach the file file.txt
to the email with the subject "Subject" and send it to [email protected]
.
You can also use the -A
option to specify multiple files to attach:
mail -s "Subject" -A file1.txt file2.txt [email protected]
This will attach both file1.txt
and file2.txt
to the email.
Note that the -a
and -A
options only work with the mail
command, not with other email clients like mutt
or msmtp
.
Also, you can use the --attach
option with the --body
option to specify the body of the email:
mail -s "Subject" --attach file.txt --body "Hello, this is a test email." [email protected]
This will attach the file file.txt
to the email and set the body of the email to "Hello, this is a test email.".
You can also use the --attach
option with the -c
option to specify the content type of the attachment:
mail -s "Subject" --attach file.txt -c "text/plain" [email protected]
This will attach the file file.txt
to the email and set the content type of the attachment to text/plain
.
It's worth noting that the mail
command is a simple command-line email client, and it may not support all the features of more advanced email clients.