Mail command in linux with attachment

The mail command in Linux is used to send emails. To send an email with an attachment, you can use the following syntax:

mail -s "Subject" -a "attachment" [email protected]

Here:

For example, to send an email with an attachment named report.pdf to [email protected], you can use the following command:

mail -s "Weekly Report" -a report.pdf [email protected]

This will send an email with the subject "Weekly Report" and attach the file report.pdf to the email.

You can also use the -c option to specify the content of the email. For example:

mail -s "Weekly Report" -c "This is a weekly report." -a report.pdf [email protected]

This will send an email with the subject "Weekly Report", the body "This is a weekly report.", and attach the file report.pdf to the email.

Note that the mail command is a simple command-line email client, and it may not support all the features of a full-fledged email client like Gmail or Outlook. If you need to send more complex emails, you may want to consider using a more advanced email client or a scripting language like Python or Perl.

Also, you can use mutt command which is a more powerful email client than mail command, it supports attachments and more features.

mutt -s "Subject" -a "attachment" [email protected]

You can also use sendmail command which is a more powerful email client than mail command, it supports attachments and more features.

sendmail -t -i -f "From Email" -s "Subject" [email protected] < message.txt

You can also use msmtp command which is a more powerful email client than mail command, it supports attachments and more features.

msmtp -a "attachment" -s "Subject" [email protected]

Please note that you need to have the msmtp package installed on your system to use it.

It's also worth noting that the mail command is not the most secure way to send emails, as it can be vulnerable to email spoofing and other security threats. If you need to send sensitive information, it's recommended to use a more secure method, such as using a secure email client or a web-based email service.