1MIME-CONSTRUCT(1)     User Contributed Perl Documentation    MIME-CONSTRUCT(1)
2
3
4

NAME

6       mime-construct - construct and optionally mail MIME messages
7

SYNOPSIS

9       mime-construct switch...
10
11       Sorry, it's hard to provide a meaningful synopsis.  See the examples.
12

DESCRIPTION

14       mime-construct constructs and (by default) mails MIME messages.  It is
15       entirely driven from the command line, it is designed to be used by
16       other programs, or people who act like programs.
17

OPTIONS

19   Global Settings
20       --debug
21           Turn debugging on.
22
23       --help
24           Show the usage message and die.
25
26       --output
27           Don't mail the generated message, print it to stdout instead.  This
28           loses --bcc info.
29
30       --subpart
31           Generate a subpart which can be used in another MIME message,
32           rather than a top-level MIME message itself.  This turns on
33           --output and changes some internal semantics a bit.  See the
34           examples.
35
36       --version
37           Print the version and exit successfully, if this is the only arg.
38           Otherwise, print the version and die.
39
40   Main Header
41       These arguments add text to the top-level header of the message, or
42       control who it gets sent to.
43
44       --bcc address
45           Add address to the recipient list.  This doesn't actually add
46           anything to the header, of course.  If you're not actually mailing
47           the message (if you use --output or --subpart) --bcc will have no
48           effect.
49
50       --cc address
51           Add an address to the Cc: list.
52
53       --embedded-to
54           Send the message to the recipients already listed in the header, in
55           addition to those given with --to, --cc, and --bcc.  This makes
56           sense if you use the --header switch to add your own To: or Cc:.
57           In this case you probably don't want to use --to or --cc because
58           they would create new headers rather than adding to the ones
59           already in the message.
60
61           This switch passes the -t switch to sendmail (mime-construct
62           doesn't try to parse the headers you provide), so it doesn't really
63           do anything if you're not mailing the message.
64
65       --header str
66           Add arbitrary text to the header.  The str can be anything you
67           like, including multiple lines.  You can create invalid messages
68           this way.  If you include a blank line in the str you'll really
69           screw up the message.
70
71       --multipart str
72           This specifies the multipart content type and options.  The default
73           is "multipart/mixed".  Don't include a "boundary" setting, that's
74           supplied by mime-construct.
75
76           It's okay if you specify the --multipart type but the message turns
77           out to be a single part, the type you supply will just be ignored.
78
79       --prelude str
80           This adds str to the multipart prelude text.  If you specify
81           --prelude multiple times the strs will all be concatenated.
82
83           There isn't any default for this text.  It seems to me that
84           nowadays adding an explanation of MIME to the beginning of a
85           message is like explaining how to use a seat buckle to people who
86           are riding in an airplane.
87
88           It's okay if you specify the --prelude but the message turns out to
89           be a single part, the prelude you supply will just be ignored.
90
91       --subject str
92           Specify the subject for the message.
93
94       --to address
95           Add an address to the To: list.
96
97   Per-part Header
98       These switches control the per-part headers.  If the message turns out
99       not to be multipart they actually add data to the top level header.
100
101       Each of these applies only to the next part output.  After each part is
102       output they are reset to their default values.  It doesn't make sense
103       to use them without a following part, so mime-construct will sputter
104       and die if you try to do that.
105
106       --attachment name
107           This adds a "Content-Disposition: attachment" header with the given
108           name as the value of the "filename" attribute.  It's just a
109           convenience, since mime-construct is often used to send files as
110           attachments.
111
112           Using --attachment name does not cause mime-construct to read any
113           data from the file called name!  It just uses that name in the
114           header.  The actual data which will go into this part of the
115           message comes from one of the regular part output switches (given
116           below).
117
118           You might prefer to use the --file-attach switch, which does read
119           from the named file.
120
121       --encoding type
122           This specifies the type of encoding you want this part to use.  You
123           normally shouldn't use this switch, though.  If this switch isn't
124           used mime-construct will choose an appropriate encoding.
125
126           The data you supply mustn't be encoded already, mime-construct will
127           encode it according to the type you specify here.  Valid encodings
128           are 7bit, 8bit, binary, quoted-printable, and base64.  It's easy to
129           generate an illegal MIME message by specifying the encoding
130           yourself.
131
132       --part-header str
133           Add arbitrary text to the per-part header.  The str can be anything
134           you like, including multiple lines.  You can create invalid
135           messages this way.  If you include a blank line in the str you'll
136           really screw up the message.
137
138       --type type
139           Specify the content type for this part.  If you don't specify a
140           --type it defaults to "text/plain".  The type you supply can
141           contain not only the type proper but also options.  The whole thing
142           will just be plopped onto the end of "Content-Type:" and stuck into
143           the header.
144
145           You might prefer to use the --file-auto or --file-attach switches,
146           which set the --type automatically based on a file's name.
147
148   Part Output
149       These switches add data to the body of the message.  You use one of
150       these for each for each part of a multipart message (or just one of
151       them if the message isn't to be multipart).
152
153       --file path
154       --file-auto path
155       --file-attach path
156       --attach path
157       --string str
158       --body str
159           Use the contents of the file path or the literal string str as the
160           body of this part.
161
162           --file-auto causes the Content-Type to be set based on the file's
163           name, if possible.
164
165           --file-attach does that and sets the --attachment name as well.
166
167           Be sure to include the trailing newline on str unless there really
168           isn't supposed to be one.  If you leave the trailing newline off
169           the part will have to be encoded in "base64" (because
170           "quoted-printable" has an artificial limitation which prevents it
171           from being able to encode such a data stream).
172
173           --attach is an alias for --file-attach, and --body is an alias for
174           --string.
175
176       --subpart-file path
177       --subpart-string str
178           Use either the contents of path or str itself as the body of this
179           part, but treat it as a subpart.  This means that the data contains
180           both some headers and some text.  It also means that you can't use
181           --type or --encoding for this part.
182
183           Normally the path or str will have been generated by a different
184           invocation of mime-construct which was given the --subpart switch.
185
186       Arguments to switches which take a file name (such as --file and
187       --subpart-file) can have some magic.  If there is no file with the path
188       supplied a regular Perl open() is done on it.  See "EXAMPLES".
189

EXAMPLES

191       The examples assume that $nl contains a newline.  The other variables
192       used are I hope self-explanatory.
193
194       Send a simple message.
195
196           mime-construct --to "$recip" --subject 'hi there' --string "$body"
197
198       Send a message which is read from stdin.
199
200           fortune | mime-construct --to "$recip" --subject fortune --file -
201
202       Send a plain text part and attach a file, setting the file's content
203       type and --attachment name automatically.
204
205           mime-construct --to "$recip" --subject "$file" \
206               --string "Here's the file I told you about.$nl" \
207               --file-attach "$file"
208
209       Most people think of attachments as multipart messages, but they don't
210       have to be.  This generates a zip of all the files in the current
211       directory and sends them as an attachment but as a single part message.
212
213           zip -q - * |
214               mime-construct --to "$recip" --subject 'zipped directory' \
215                   --attachment dir.zip --type application/zip --file -
216
217       You can use the full expressiveness of Perl's open() when constructing
218       file names.  Eg, you can run processes XXX bad examples, there's no
219       file names
220
221           mime-construct --to "$recip" --subject "$subject" \
222            --string "Here are those two files you wanted.$nl" \
223            --type application/x-gzip --attachment file1.gz --file 'gzip -c file1 |' \
224            --type application/x-gzip --attachment file1.gz --file 'gzip -c file2 |'
225
226       or read from alternate file descriptors ("<&=4" to read from file
227       descriptor 4) or whatever.  See perlopentut for a tutorial.
228
229       Here's an example of using a separate invocation of mime-construct to
230       create a subpart.  This creates a message which has two parts at the
231       top level.  The first part is some text, the second part is a digest.
232       The digest itself is a multipart message which contains a number of
233       message/rfc822 parts.
234
235           msg_args=
236           for msg in $msg_list
237           do
238               msg_args="$msg_args --type message/rfc822 --file $msg"
239           done
240
241           set fnord
242           for recip in $recip_list
243           do
244               set "$@" --bcc $recip
245           done
246           shift
247
248           mime-construct --subpart --multipart multipart/digest $msg_args |
249               mime-construct \
250                   --header "To: Digest recipients:;$nl" \
251                   --subject 'Foo digest' \
252                   "$@" \
253                   --file "$introduction" \
254                   --subpart-file -
255
256       Here is how to send an encrypted messages (multipart/encrypted, as
257       defined in RFC 1847).  You use mime-construct "--subpart" to generate
258       the real message you want to send (which can be kind of MIME message --
259       non-text, multi-part, what have you), then encrypt that and use another
260       mime-construct to contruct and send the multipart/encrypted message
261       which contains it.
262
263           enc_type=application/pgp-encrypted
264           enc_params="Version: 1$nl"
265
266           mime-construct --subpart --file body --file-auto image.jpg |
267             gpg --encrypt --armor -r "$recip" |
268             mime-construct --output \
269               --to "$recip" \
270               --subject "$subject" \
271               --multipart "multipart/encrypted; protocol=\"$enc_type\"" \
272               --type "$enc_type" \
273               --string "$enc_params" \
274               --type application/octet-stream \
275               --file -
276

BUGS

278       The body of the message is always held in memory, so you can expect
279       problems if you work with bodies which are large compared to the amount
280       of memory you've got.
281

AVAILABILITY

283       The code is licensed under the GNU GPL.  Check
284       http://www.argon.org/~roderick/ for updated versions.
285

AUTHOR

287       Roderick Schertler <roderick@argon.org>
288
289
290
291perl v5.38.0                      2023-07-21                 MIME-CONSTRUCT(1)
Impressum