How to send a mail with attachment in linux
There are several ways to send a mail with an attachment in Linux. Here are a few methods:
Method 1: Using mutt
command
You can use the mutt
command-line email client to send a mail with an attachment. Here's an example:
mutt -s "Subject" [email protected] -a attachment_file.txt
Replace Subject
with the subject of your email, [email protected]
with the recipient's email address, and attachment_file.txt
with the name of the file you want to attach.
Method 2: Using mail
command
You can use the mail
command to send a mail with an attachment. Here's an example:
mail -s "Subject" [email protected] < attachment_file.txt
Replace Subject
with the subject of your email, [email protected]
with the recipient's email address, and attachment_file.txt
with the name of the file you want to attach.
Method 3: Using sendmail
command
You can use the sendmail
command to send a mail with an attachment. Here's an example:
sendmail -t -i -f [email protected] [email protected] < attachment_file.txt
Replace [email protected]
with your email address, [email protected]
with the recipient's email address, and attachment_file.txt
with the name of the file you want to attach.
Method 4: Using msmtp
command
You can use the msmtp
command to send a mail with an attachment. Here's an example:
msmtp -a attachment_file.txt -s "Subject" [email protected]
Replace Subject
with the subject of your email, [email protected]
with the recipient's email address, and attachment_file.txt
with the name of the file you want to attach.
Method 5: Using a GUI email client
You can also use a GUI email client like Evolution, Thunderbird, or KMail to send a mail with an attachment. These clients usually have a built-in attachment feature that allows you to select a file to attach.
Tips
- Make sure to replace
[email protected]
with the actual email address of the recipient. - Make sure to replace
attachment_file.txt
with the actual name of the file you want to attach. - You can use the
-c
option withmutt
ormail
to specify the content type of the attachment (e.g.,-c text/plain
for a plain text file). - You can use the
-f
option withsendmail
to specify the sender's email address. - You can use the
-a
option withmsmtp
to specify the attachment file.