diff options
author | Diego Nehab <diego.nehab@gmail.com> | 2016-03-04 15:36:32 -0300 |
---|---|---|
committer | Diego Nehab <diego.nehab@gmail.com> | 2016-03-04 15:36:32 -0300 |
commit | 944305dc21350fd2ec32a9552d893da86894fd62 (patch) | |
tree | 82948c24dade5e0da6924ab5e706f146bce4692a /doc/smtp.html | |
parent | cdce73b226cc4da6a073b79bec02a6780d32ff1a (diff) | |
download | luasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.gz luasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.bz2 luasocket-944305dc21350fd2ec32a9552d893da86894fd62.zip |
Added gettimeout for completeness.
Also documented.
Rordered manuals so order is alphabetical.
Diffstat (limited to 'doc/smtp.html')
-rw-r--r-- | doc/smtp.html | 235 |
1 files changed, 118 insertions, 117 deletions
diff --git a/doc/smtp.html b/doc/smtp.html index bbbff80..600ec37 100644 --- a/doc/smtp.html +++ b/doc/smtp.html | |||
@@ -114,6 +114,124 @@ the SMTP module: | |||
114 | <li> <tt>ZONE</tt>: default time zone. | 114 | <li> <tt>ZONE</tt>: default time zone. |
115 | </ul> | 115 | </ul> |
116 | 116 | ||
117 | <!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
118 | |||
119 | <p class=name id=message> | ||
120 | smtp.<b>message(</b>mesgt<b>)</b> | ||
121 | </p> | ||
122 | |||
123 | <p class=description> | ||
124 | Returns a <em>simple</em> | ||
125 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep). | ||
126 | </p> | ||
127 | |||
128 | <p class=parameters> | ||
129 | The only parameter of the function is a table describing the message. | ||
130 | <tt>Mesgt</tt> has the following form (notice the recursive structure): | ||
131 | </p> | ||
132 | |||
133 | <blockquote> | ||
134 | <table summary="Mesgt table structure"> | ||
135 | <tr><td><tt> | ||
136 | mesgt = {<br> | ||
137 | headers = <i>header-table</i>,<br> | ||
138 | body = <i>LTN12 source</i> or <i>string</i> or | ||
139 | <i>multipart-mesgt</i><br> | ||
140 | }<br> | ||
141 | <br> | ||
142 | multipart-mesgt = {<br> | ||
143 | [preamble = <i>string</i>,]<br> | ||
144 | [1] = <i>mesgt</i>,<br> | ||
145 | [2] = <i>mesgt</i>,<br> | ||
146 | ...<br> | ||
147 | [<i>n</i>] = <i>mesgt</i>,<br> | ||
148 | [epilogue = <i>string</i>,]<br> | ||
149 | }<br> | ||
150 | </tt></td></tr> | ||
151 | </table> | ||
152 | </blockquote> | ||
153 | |||
154 | <p class=parameters> | ||
155 | For a simple message, all that is needed is a set of <tt>headers</tt> | ||
156 | and the <tt>body</tt>. The message <tt>body</tt> can be given as a string | ||
157 | or as a <em>simple</em> | ||
158 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> | ||
159 | source. For multipart messages, the body is a table that | ||
160 | recursively defines each part as an independent message, plus an optional | ||
161 | <tt>preamble</tt> and <tt>epilogue</tt>. | ||
162 | </p> | ||
163 | |||
164 | <p class=return> | ||
165 | The function returns a <em>simple</em> | ||
166 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> | ||
167 | source that produces the | ||
168 | message contents as defined by <tt>mesgt</tt>, chunk by chunk. | ||
169 | Hopefully, the following | ||
170 | example will make things clear. When in doubt, refer to the appropriate RFC | ||
171 | as listed in the introduction. </p> | ||
172 | |||
173 | <pre class=example> | ||
174 | -- load the smtp support and its friends | ||
175 | local smtp = require("socket.smtp") | ||
176 | local mime = require("mime") | ||
177 | local ltn12 = require("ltn12") | ||
178 | |||
179 | -- creates a source to send a message with two parts. The first part is | ||
180 | -- plain text, the second part is a PNG image, encoded as base64. | ||
181 | source = smtp.message{ | ||
182 | headers = { | ||
183 | -- Remember that headers are *ignored* by smtp.send. | ||
184 | from = "Sicrano de Oliveira <sicrano@example.com>", | ||
185 | to = "Fulano da Silva <fulano@example.com>", | ||
186 | subject = "Here is a message with attachments" | ||
187 | }, | ||
188 | body = { | ||
189 | preamble = "If your client doesn't understand attachments, \r\n" .. | ||
190 | "it will still display the preamble and the epilogue.\r\n" .. | ||
191 | "Preamble will probably appear even in a MIME enabled client.", | ||
192 | -- first part: no headers means plain text, us-ascii. | ||
193 | -- The mime.eol low-level filter normalizes end-of-line markers. | ||
194 | [1] = { | ||
195 | body = mime.eol(0, [[ | ||
196 | Lines in a message body should always end with CRLF. | ||
197 | The smtp module will *NOT* perform translation. However, the | ||
198 | send function *DOES* perform SMTP stuffing, whereas the message | ||
199 | function does *NOT*. | ||
200 | ]]) | ||
201 | }, | ||
202 | -- second part: headers describe content to be a png image, | ||
203 | -- sent under the base64 transfer content encoding. | ||
204 | -- notice that nothing happens until the message is actually sent. | ||
205 | -- small chunks are loaded into memory right before transmission and | ||
206 | -- translation happens on the fly. | ||
207 | [2] = { | ||
208 | headers = { | ||
209 | ["content-type"] = 'image/png; name="image.png"', | ||
210 | ["content-disposition"] = 'attachment; filename="image.png"', | ||
211 | ["content-description"] = 'a beautiful image', | ||
212 | ["content-transfer-encoding"] = "BASE64" | ||
213 | }, | ||
214 | body = ltn12.source.chain( | ||
215 | ltn12.source.file(io.open("image.png", "rb")), | ||
216 | ltn12.filter.chain( | ||
217 | mime.encode("base64"), | ||
218 | mime.wrap() | ||
219 | ) | ||
220 | ) | ||
221 | }, | ||
222 | epilogue = "This might also show up, but after the attachments" | ||
223 | } | ||
224 | } | ||
225 | |||
226 | -- finally send it | ||
227 | r, e = smtp.send{ | ||
228 | from = "<sicrano@example.com>", | ||
229 | rcpt = "<fulano@example.com>", | ||
230 | source = source, | ||
231 | } | ||
232 | </pre> | ||
233 | |||
234 | |||
117 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 235 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
118 | 236 | ||
119 | <p class=name id=send> | 237 | <p class=name id=send> |
@@ -275,123 +393,6 @@ r, e = smtp.send{ | |||
275 | } | 393 | } |
276 | </pre> | 394 | </pre> |
277 | 395 | ||
278 | <!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
279 | |||
280 | <p class=name id=message> | ||
281 | smtp.<b>message(</b>mesgt<b>)</b> | ||
282 | </p> | ||
283 | |||
284 | <p class=description> | ||
285 | Returns a <em>simple</em> | ||
286 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep). | ||
287 | </p> | ||
288 | |||
289 | <p class=parameters> | ||
290 | The only parameter of the function is a table describing the message. | ||
291 | <tt>Mesgt</tt> has the following form (notice the recursive structure): | ||
292 | </p> | ||
293 | |||
294 | <blockquote> | ||
295 | <table summary="Mesgt table structure"> | ||
296 | <tr><td><tt> | ||
297 | mesgt = {<br> | ||
298 | headers = <i>header-table</i>,<br> | ||
299 | body = <i>LTN12 source</i> or <i>string</i> or | ||
300 | <i>multipart-mesgt</i><br> | ||
301 | }<br> | ||
302 | <br> | ||
303 | multipart-mesgt = {<br> | ||
304 | [preamble = <i>string</i>,]<br> | ||
305 | [1] = <i>mesgt</i>,<br> | ||
306 | [2] = <i>mesgt</i>,<br> | ||
307 | ...<br> | ||
308 | [<i>n</i>] = <i>mesgt</i>,<br> | ||
309 | [epilogue = <i>string</i>,]<br> | ||
310 | }<br> | ||
311 | </tt></td></tr> | ||
312 | </table> | ||
313 | </blockquote> | ||
314 | |||
315 | <p class=parameters> | ||
316 | For a simple message, all that is needed is a set of <tt>headers</tt> | ||
317 | and the <tt>body</tt>. The message <tt>body</tt> can be given as a string | ||
318 | or as a <em>simple</em> | ||
319 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> | ||
320 | source. For multipart messages, the body is a table that | ||
321 | recursively defines each part as an independent message, plus an optional | ||
322 | <tt>preamble</tt> and <tt>epilogue</tt>. | ||
323 | </p> | ||
324 | |||
325 | <p class=return> | ||
326 | The function returns a <em>simple</em> | ||
327 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> | ||
328 | source that produces the | ||
329 | message contents as defined by <tt>mesgt</tt>, chunk by chunk. | ||
330 | Hopefully, the following | ||
331 | example will make things clear. When in doubt, refer to the appropriate RFC | ||
332 | as listed in the introduction. </p> | ||
333 | |||
334 | <pre class=example> | ||
335 | -- load the smtp support and its friends | ||
336 | local smtp = require("socket.smtp") | ||
337 | local mime = require("mime") | ||
338 | local ltn12 = require("ltn12") | ||
339 | |||
340 | -- creates a source to send a message with two parts. The first part is | ||
341 | -- plain text, the second part is a PNG image, encoded as base64. | ||
342 | source = smtp.message{ | ||
343 | headers = { | ||
344 | -- Remember that headers are *ignored* by smtp.send. | ||
345 | from = "Sicrano de Oliveira <sicrano@example.com>", | ||
346 | to = "Fulano da Silva <fulano@example.com>", | ||
347 | subject = "Here is a message with attachments" | ||
348 | }, | ||
349 | body = { | ||
350 | preamble = "If your client doesn't understand attachments, \r\n" .. | ||
351 | "it will still display the preamble and the epilogue.\r\n" .. | ||
352 | "Preamble will probably appear even in a MIME enabled client.", | ||
353 | -- first part: no headers means plain text, us-ascii. | ||
354 | -- The mime.eol low-level filter normalizes end-of-line markers. | ||
355 | [1] = { | ||
356 | body = mime.eol(0, [[ | ||
357 | Lines in a message body should always end with CRLF. | ||
358 | The smtp module will *NOT* perform translation. However, the | ||
359 | send function *DOES* perform SMTP stuffing, whereas the message | ||
360 | function does *NOT*. | ||
361 | ]]) | ||
362 | }, | ||
363 | -- second part: headers describe content to be a png image, | ||
364 | -- sent under the base64 transfer content encoding. | ||
365 | -- notice that nothing happens until the message is actually sent. | ||
366 | -- small chunks are loaded into memory right before transmission and | ||
367 | -- translation happens on the fly. | ||
368 | [2] = { | ||
369 | headers = { | ||
370 | ["content-type"] = 'image/png; name="image.png"', | ||
371 | ["content-disposition"] = 'attachment; filename="image.png"', | ||
372 | ["content-description"] = 'a beautiful image', | ||
373 | ["content-transfer-encoding"] = "BASE64" | ||
374 | }, | ||
375 | body = ltn12.source.chain( | ||
376 | ltn12.source.file(io.open("image.png", "rb")), | ||
377 | ltn12.filter.chain( | ||
378 | mime.encode("base64"), | ||
379 | mime.wrap() | ||
380 | ) | ||
381 | ) | ||
382 | }, | ||
383 | epilogue = "This might also show up, but after the attachments" | ||
384 | } | ||
385 | } | ||
386 | |||
387 | -- finally send it | ||
388 | r, e = smtp.send{ | ||
389 | from = "<sicrano@example.com>", | ||
390 | rcpt = "<fulano@example.com>", | ||
391 | source = source, | ||
392 | } | ||
393 | </pre> | ||
394 | |||
395 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 396 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
396 | 397 | ||
397 | <div class=footer> | 398 | <div class=footer> |