Mailx example with attachment
Here is an example of using the mailx
command to send an email with an attachment:
Example:
mailx -s "Example Email with Attachment" [email protected] << EOF
Subject: Example Email with Attachment
This is an example email with an attachment.
Attachment: example.txt
EOF
In this example:
mailx
is the command used to send the email.-s
is the option to specify the subject of the email.[email protected]
is the email address of the recipient.<< EOF
is used to define the email body.Subject: Example Email with Attachment
is the subject of the email.This is an example email with an attachment.
is the body of the email.Attachment: example.txt
specifies the attachment file.
Note: The attachment file example.txt
should be in the same directory as the command is run from.
Example with multiple attachments:
mailx -s "Example Email with Multiple Attachments" [email protected] << EOF
Subject: Example Email with Multiple Attachments
This is an example email with multiple attachments.
Attachment: example1.txt
Attachment: example2.txt
Attachment: example3.txt
EOF
In this example, we are attaching three files: example1.txt
, example2.txt
, and example3.txt
.
Example with a file in a different directory:
mailx -s "Example Email with Attachment" [email protected] << EOF
Subject: Example Email with Attachment
This is an example email with an attachment.
Attachment: /path/to/example.txt
EOF
In this example, we are attaching a file located at /path/to/example.txt
. Make sure to specify the full path to the file.
Note: The mailx
command may not work as expected if you are using a modern email client or a web-based email service. In that case, you may need to use a different command or tool to send emails with attachments.