{
    "mode": "man",
    "parameter": "makemime",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/makemime/1/json",
    "generated": "2026-07-05T22:12:55Z",
    "synopsis": "makemime [options...]\nmakemime [@filename]",
    "sections": {
        "NAME": {
            "content": "makemime - Create MIME-formatted messages\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "makemime [options...]\n\nmakemime [@filename]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "makemime creates MIME-formatted messages of arbitrary complexity.  makemime reads one or more\nindividual files, MIME-encodes them, adds basic MIME headers, and adds any additional headers\nspecified bye command line options. The result is saved to another file or standard output.\nComplex MIME-formatted messages are created by piping together multiple instances of\nmakemime. Advanced options direct makemime to fork() itself, and handle the details of\nsetting up all the pipelines.\n\nIn most cases, options for makemime come directly from the command line. @filename reads the\noptions from a file. \"@&n\" reads options from a pipe on file descriptor #n. \"@-\" is a\nshortcut for \"@&0\", which reads options from standard input.\n\nWhen options are read from a file or a pipe, each option must be on a line by itself. If an\noption requires an argument, the argument must follow on the next line.\n\nFor readability, leading whitespace is deleted when options are read from a file or a pipe.\nEmpty lines are also ignored, as well as lines that begin with the '#' character.\n\nOptions and their arguments may contain characters that are special characters to the shell,\nsuch as '(' and ')'. These characters must be backslashed when specified on the command line,\nto avoid their special meaning to the shell. These characters MUST NOT be backslashed when\noptions are read from a file or a pipe. Similarly, the contents of most headers nearly always\ninclude spaces. Therefore they must be quoted when specified on the command line. Header\ncontents MUST NOT be quoted when options come from a file or a pipe.\n\nmakemime reads the content to be formatted as a MIME message from some other file. The files\ncan also be a pipe. It is possible to supply both the options and a file from the same pipe,\nby terminating the options list with a line containing the single character \"-\". The\nremainder of the pipe will be available to be used as an input file (which must be explicitly\nspecified by one of the options). Of course, only one input file can come from a single pipe.\n",
            "subsections": [
                {
                    "name": "MIME overview",
                    "content": "A MIME-formatted message contains one or several MIME sections. MIME headers specify how\nmultiple MIME sections are to be interpreted as a whole (whether they are attached together;\nwhether they are alternative representations of the same content; or something even more\nesoteric). This manual page gives a very brief, terse, overview of basic MIME concepts. The\ndescription is biased towards describing the functionality of the makemime utility. See RFC\n2045[1], RFC 2046[2], RFC 2047[3], RFC 2048[4], and RFC 2049[4] for a formal definition of\nMIME-formatted messages.\n\nEach file in a MIME message is encoded as a single MIME section. A MIME section consists of\nat least one header line, \"Content-Type:\". The \"Content-Type:\" header gives the type of the\ndata ontained in the file. Other header lines may also be present. Their relative order does\nnot matter. MIME headers are followed by a blank line, then the contents of the file, encoded\nappropriately. All MIME sections generated by makemime will always contain another header,\n\"Content-Transfer-Encoding:\". This header gives the encoding method used for the file; it is\nan optional header, but makemime always creates it.\n\nThe MIME encoding method defaults to \"7bit\" if this header is absent.  7bit encoding is only\nsuitable for plain text messages in the US-ASCII character set. The \"8bit\" encoding method is\nused by plain text messages in other character sets that use octets with the high bit set. An\nalternative to 8bit encoding is \"quoted-printable\". The \"base64\" encoding method is used for\nfiles containing binary data (anything other than plain text).\n\nMIME sections that contain text messages have their \"Content-Type:\" header set to\n\"text/plain\"; or \"text/html\" for HTML messages. There are also several other, rare, content\ntypes that can be used. MIME sections that contain other kinds of data will use some other,\nappropriate \"Content-Type:\" header, such as \"image/gif\", or \"audio/x-wav\".\n\nMIME sections that contain textual content may also use the base64 encoding method, they are\nnot required to use 7bit, 8bit, or quoted-printable. \"text/pdf\" sections, that contain PDF\nfiles, typically contain binary data and must use the base64 encoding. Consequently, MIME\nsections that typically contain binary data, such as image/gif and audio/x-wav, are free to\nuse encodings other than base64, as long as all the data can be represented by printable\ncharacters (but, in practice, that never happens).\n\nMIME sections may also contain other, optional, headers such as \"Content-Disposition:\",\n\"Content-ID:\", and \"Content-Name:\". Consult the appropriate RFCs for the specific usage of\nthese headers. These headers can be added by makemime by using the -a option, as described\nbelow. These headers play no part in creating the overall structure of a MIME-encoded\nmessage, and makemime does not care much about these headers. It simply includes them, and\ntheir content, upon request.\n\nMultiple files are formatted as a single message MIME message in two steps: first, by\ncreating a MIME section for each file; and then creating a single MIME section that contains\nother MIME sections. A \"multipart/mixed\" MIME section contains a collection of MIME sections\nthat represent different objects, attached together. A \"multipart/alternative\" MIME section\ncontains a collection of MIME sections which are alternative representations of the same\nobject, such as an HTML and a plain text version of the same message. Other \"multipart\" MIME\nsections also exist, and their usage is defined by their respective RFCs.\n"
                },
                {
                    "name": "Creating a single MIME section",
                    "content": "makemime {-c \"type\"} [-e \"encoding\"] [-o outputfile] [-C \"charset\"] [-N \"name\"]\n[-a \"header: value\"...] {filename}\n\nThe -c option reads filename, encodes it appropriately, adds the \"Content-Type: type\" and\n\"Content-Transfer-Encoding:\" MIME headers, then writes the result to standard output.  type\ncan be any valid MIME type, except for multipart. Setting filename to \"-\" reads from standard\ninput. Setting filename to \"&n\" reads from file descriptor #n.\n\nThe -C option sets the MIME charset attribute for text/plain content. The -N option sets the\nname attribute for Content-Type:.\n\nencoding argument should be specified. It's more efficient to do so.  encoding must be one of\nthe following: 7bit, 8bit, quoted-printable, or base64.\n\nIf encoding is not specified, makemime reads the filename twice - once to figure out the best\nencoding method, and the second time to encode filename. If filename is a pipe makemime\ncreates a temporary file, which is not very efficient if filename is large. However letting\nmakemime pick the encoding method is more convenient if filename is relatively small.\n\nAnother possibility is to omit encoding and set type to auto. This combination sets\n\"Content-Type:\" to either text/plain, or application/octet-stream, based on the selected\nencoding.\n\nBy default the encoded MIME section is written to standard output. The -o option writes the\nMIME section to outputfile.  outputfile may be \"&n\", which writes the MIME section to a pipe\non file descriptor #n.\n\nmakemime does not generate any other headers. Particularly, the \"Mime-Version:\" header is\nrequired for MIME-formatted E-mail messages. Additional headers are specified by the -a\noption, which may be used multiple times to insert multiple headers.  makemime doesn't do\nanything with them except to insert the headers into the generated MIME section.\n\nNote that \"Mime-Version:\" is only required for the top level MIME section. This header is not\nrequired for individual MIME sections that are later combined into a multipart MIME\ncollection.\n\nNote\nThe -c option must occur listed first, the remaining options must follow the -c option.\n"
                },
                {
                    "name": "Creating a multipart MIME collection",
                    "content": "makemime {-m \"multipart/type\"} [-e \"encoding\"] [-o outputfile] [-a \"header: value\"...]\n{filename}\n\nThe -m option is identical to the -c option, except for three differences.\n\ntype must be either \"multipart/mixed\", \"multipart/alternative\", or some other MIME multipart\ncontent type. Additionally, \"encoding\" can only be \"7bit\" or \"8bit\", and will default to\n\"8bit\" if not specified. Finally, filename must be a MIME-formatted section, NOT a regular\nfile. Usually filename is created by a previous invocation of makemime (it can also be a\npipe, like the -c option), but it can be created via any other means.\n\nThe -m option creates an initial multipart MIME collection, that contains only one MIME\nsection, taken from filename. The collection is written to standard output, or the pipe or to\noutputfile.\n"
                },
                {
                    "name": "Creating a multipart MIME section",
                    "content": "makemime {-j file1\"} [-o outputfile] {file2}\n\nThis option adds a MIME section to an existing MIME collection.  file1 must be a MIME\ncollection that was previously created by the -m option.  file2 must be a MIME section that\nwas previously created by the -c option. The -j options adds the MIME section in file2 to the\nMIME collection in file1. The result is written to standard output or to outputfile.\n\nfile1 and/or file2 may be \"@&n\" which reads from file descriptor #n. The outputfile may also\nspecify a file descriptor.\n\nfile1 and file2 should ideally be created by makemime as well. It's also possible to use\nMIME-formatted files created by other software, but with some degree of care.  makemime is\nnot intended to be a MIME parser, but a MIME generator. However some amount of MIME parsing\nis necessary to append a MIME section to an existing MIME collection.  makemime's parsing is\nsufficient for appending a new section to a MIME collection, as long as the MIME headers in\nthe MIME collections are straightforward. Very convoluted MIME headers may confuse makemime,\nand it may not be able to handle them.\n"
                },
                {
                    "name": "Recursive MIME collections",
                    "content": "MIME collection may contain other MIME collections as well as MIME sections. The -m and the"
                },
                {
                    "name": "-j",
                    "content": "because a multipart MIME collection is just a special type of a MIME section. The following\nexample encodes a text message that can be alternatively represented as HTML or plain text,\nwith some additional attachments:\n\n1. Create a MIME collection that has a text/plain and a text/html MIME section.\n\n2. Create a MIME collection consisting of the MIME section generated in step one, plus\nadditional MIME sections containing other attachments.\n\nFor example:\n\n# Take two files containing the text and the html version of a message, and\n# add MIME headers to them.\n\nmakemime -c \"text/plain; charset=iso-8859-1\" -o tmp1.txt msg.txt\nmakemime -c \"text/html; charset=iso-8859-1\" -o tmp1.html msg.html\n\n# Combine the result into a multipart/alternative collection\n\nmakemime -m \"multipart/alternative\" -a \"Content-Disposition: inline\" \\\n-o tmp.ma1 tmp1.txt\nmakemime -j tmp.ma1 -o tmp.ma2 tmp1.html\n\n# Add MIME headers to an image attachment.\n\nmakemime -c \"image/gif\" -a \"Content-Disposition: attachment\" \\\n-o tmp2.gif attachment.gif\n\n# Create the final multipart/mixed collection\n\nmakemime -m \"multipart/mixed\" -a \"Mime-Version: 1.0\" \\\n-o tmp.mm1 tmp.ma2\nmakemime -j tmp.mm1 -o output.msg tmp2.gif\n\noutput.msg now contains the complete MIME collection. Just add the Subject:, From:, and To:\nheaders (can also be done by additional -a options, of course), and send it on its way.\n",
                    "flag": "-j"
                },
                {
                    "name": "Building complex MIME encodings",
                    "content": "There are several different ways to build complete MIME encodings from multiple MIME\nsections. One way is to use temporary files to create MIME sections, then combine them\ntogether into a single MIME collection. A slightly more complicated approach involves setting\nup pipes between multiple makemime processes, in order to avoid using temporary files.\n\nThis can be done manually, by hand. It is also possible to have makemime do this\nautomatically.  makemime will set up these pipes and run multiple instances of itself to\ncreate a single MIME collection, with multiple attachments of complexity limited only by your\nsystem's limit on the maximum number of open files and pipes.\n\nAny file that's read by the -c, -m, and -j options ( -o specifies a file to create, and\ndoesn't count) may be replaced by a single argument containing a left parenthesis, additional\noptions, then a single argument containing a right parenthesis. A single invocation of\nmakemime can only use one -c, -m, or -j option. However, another -c, -m, or -j option may be\nspecified inside the left and the right parenthesis, and its output is used in place of the\nfile it replaced. In the previous example the third and the fourth invocation of makemime can\nbe replaced with the following command:\n\nmakemime -j \\(                                           \\\n-m \"multipart/alternative\"                \\\n-a \"Content-Disposition: inline\" tmp1.txt \\\n\\) -o tmp.ma2                               \\\ntmp1.html\n\nNote that the parenthesis must be backslashed, to avoid their special meaning to the shell.\nAn equivalent argument file would have the following contents:\n\n-j\n(\n-m\nmultipart/alternative\n-a\nContent-Disposition: inline\ntmp1.txt\n)\n-o\ntmp.ma2\ntmp1.html\n\nThese constructs can be arbitrarily nested, and are limited by the amount of available memory\nand resources. The entire sequence in the previous section is equivalent to the following\ncommand:\n\nmakemime -j                                                 \\\n\\(                                                 \\\n-m \"multipart/mixed\"                            \\\n-a \"Mime-Version: 1.0\"                          \\\n\\(                                              \\\n-j                                          \\\n\\(                                          \\\n-m \"multipart/alternative\"               \\\n-a \"Content-Disposition: inline\"         \\\n\\(                                       \\\n-c \"text/plain; charset=iso-8859-1\"   \\\nmsg.txt                               \\\n\\)                                       \\\n\\)                                          \\\n\\(                                          \\\n-c \"text/html; charset=iso-8859-1\"      \\\nmsg.html                                \\\n\\)                                          \\\n\\)                                              \\\n\\)                                                 \\\n-o output.msg                                      \\\n\\(                                                 \\\n-c \"image/gif\"                                  \\\n-a \"Content-Disposition: attachment\"            \\\nattachment.gif                                  \\\n\\)\n\nAn equivalent argument file would be:\n\n-j\n(\n-m\nmultipart/mixed\n-a\nMime-Version: 1.0\n(\n-j\n(\n-m\nmultipart/alternative\n-a\nContent-Disposition: inline\n(\n-c\ntext/plain; charset=iso-8859-1\nmsg.txt\n)\n)\n(\n-c\ntext/html; charset=iso-8859-1\nmsg.html\n)\n)\n)\n-o\noutput.msg\n(\n-c\nimage/gif\n-a\nContent-Disposition: attachment\nattachment.gif\n)\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "maildrop(1)[5], maildropfilter(5)[6], reformail(1)[7], reformime(1)[8], egrep(1), grep(1),\ncourier(8)[9], sendmail(8), RFC 2045[1], RFC 2046[2], RFC 2047[3], RFC 2048[4], RFC 2049[4].\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "",
            "subsections": [
                {
                    "name": "Sam Varshavchik",
                    "content": "Author\n"
                }
            ]
        },
        "NOTES": {
            "content": "1. RFC 2045\nhttp://www.rfc-editor.org/rfc/rfc2045.txt\n\n2. RFC 2046\nhttp://www.rfc-editor.org/rfc/rfc2046.txt\n\n3. RFC 2047\nhttp://www.rfc-editor.org/rfc/rfc2047.txt\n\n4. RFC 2048\nhttp://www.rfc-editor.org/rfc/rfc2048.txt\n\n5. maildrop(1)\n[set $man.base.url.for.relative.links]/maildrop.html\n\n6. maildropfilter(5)\n[set $man.base.url.for.relative.links]/maildropfilter.html\n\n7. reformail(1)\n[set $man.base.url.for.relative.links]/reformail.html\n\n8. reformime(1)\n[set $man.base.url.for.relative.links]/reformime.html\n\n9. courier(8)\n[set $man.base.url.for.relative.links]/courier.html\n\n\n\nCourier Mail Server                          06/20/2015                                  MAKEMIME(1)",
            "subsections": []
        }
    },
    "summary": "makemime - Create MIME-formatted messages",
    "flags": [
        {
            "flag": "-j",
            "long": null,
            "arg": null,
            "description": "because a multipart MIME collection is just a special type of a MIME section. The following example encodes a text message that can be alternatively represented as HTML or plain text, with some additional attachments: 1. Create a MIME collection that has a text/plain and a text/html MIME section. 2. Create a MIME collection consisting of the MIME section generated in step one, plus additional MIME sections containing other attachments. For example: # Take two files containing the text and the html version of a message, and # add MIME headers to them. makemime -c \"text/plain; charset=iso-8859-1\" -o tmp1.txt msg.txt makemime -c \"text/html; charset=iso-8859-1\" -o tmp1.html msg.html # Combine the result into a multipart/alternative collection makemime -m \"multipart/alternative\" -a \"Content-Disposition: inline\" \\ -o tmp.ma1 tmp1.txt makemime -j tmp.ma1 -o tmp.ma2 tmp1.html # Add MIME headers to an image attachment. makemime -c \"image/gif\" -a \"Content-Disposition: attachment\" \\ -o tmp2.gif attachment.gif # Create the final multipart/mixed collection makemime -m \"multipart/mixed\" -a \"Mime-Version: 1.0\" \\ -o tmp.mm1 tmp.ma2 makemime -j tmp.mm1 -o output.msg tmp2.gif output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "maildrop",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/maildrop/1/json"
        },
        {
            "name": "maildropfilter",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/maildropfilter/5/json"
        },
        {
            "name": "reformail",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/reformail/1/json"
        },
        {
            "name": "reformime",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/reformime/1/json"
        },
        {
            "name": "egrep",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/egrep/1/json"
        },
        {
            "name": "grep",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/grep/1/json"
        },
        {
            "name": "courier",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/courier/8/json"
        },
        {
            "name": "sendmail",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sendmail/8/json"
        }
    ]
}