Normally, each new attachment represents a new piece of data. The entire script can be downloaded here. The script begins with the usual prologue stating the modules that will be used: Each attachment is named after the mountpoint it describes. It scans all mounted file systems for executable files that have setuid or setgid bits set and reports the names of those files in separate attachments. The following Perl program serves as an example of using mail from a script to construct a MIME message on the fly. The above example is equivalent to:Īttachments created with this option have neither filename nor description set, so normally the use of -content-name and/or -content-filename is advised. The -attach-fd= N instructs the program to read the data to be attached from the file descriptor N. Special option is provided to facilitate the use of mail in scripts. This option disables the interactive mode and sets nonullbodymsg implicitly, so that the above example can be rewritten as: The option -attach=- forces mail to read the file to be attached from the standard input stream. $ mail -E 'set nonullbodymsg' -attach=archive.tar < /dev/null To suppress this message, unset the nullbodymsg variable, as shown in the example below:
![mail command in linux with attachment mail command in linux with attachment](https://www.poftut.com/wp-content/uploads/2020/04/image-67.png)
This will normally produce a message saying: If that's not needed, the non-interactive use can be forced by redirecting /dev/null to the standard input, e.g.:
![mail command in linux with attachment mail command in linux with attachment](https://i.stack.imgur.com/6CJM8.png)
Both of these options affect only the next -attach (or -attach-fd, see below) option.Īll the examples above will enter the usual interactive shell, allowing you to compose the body of the message. However, you can change either or both of them using the -content-name and -content-filename, correspondingly. Normally, these are the same as the file name supplied with the -attach option. content-type=application/x-tar -encoding=base64 \Įach attachment can also be assigned a description and a file name. $ mail -content-type=text/html -encoding=quoted-printable \ As well as -content-type, this option affects all attachments supplied after it in the command line, until changed by the eventual next appearance of the same option. Similarly, the encoding to use is set up by the -encoding option. content-type=application/x-tar -attach=archive.tar $ mail -content-type=text/html -attach=in.html \ For example, to send both the HTML file and the archive: To change the content type, simply add another -content-type option. The -content-type option affects all -attach options that follow it. $ mail -content-type=text/html -attach=in.html To change the content type, use the -content-type option. For example, the following will attach the content of the file archive.tar:īy default, the content type will be set to application/octet-stream, and the attachment will be encoded using the base64 encoding.
![mail command in linux with attachment mail command in linux with attachment](https://opensource.com/sites/default/files/uploads/alpine_main_menu.png)
Its argument specifies the file to attach. The simplest way to attach a file from command line is by using the -attach ( -A) option. It makes special emphasis on using mail from scripts.
#MAIL COMMAND IN LINUX WITH ATTACHMENT HOW TO#
This article describes how to create attachments using the mail utility.