1smtp(n) smtp client smtp(n)
2
3
4
5______________________________________________________________________________
6
8 smtp - Client-side tcl implementation of the smtp protocol
9
11 package require Tcl
12
13 package require mime ?1.5.4?
14
15 package require smtp ?1.4.5?
16
17 ::smtp::sendmessage token option...
18
19______________________________________________________________________________
20
22 The smtp library package provides the client side of the Simple Mail
23 Transfer Protocol (SMTP) (1) (2).
24
25 ::smtp::sendmessage token option...
26 This command sends the MIME part (see package mime) represented
27 by token to an SMTP server. options is a list of options and
28 their associated values. The recognized options are:
29
30 -servers
31 A list of SMTP servers. The default is localhost.
32
33 -ports A list of SMTP ports. The default is 25.
34
35 -client
36 The name to use as our hostname when connecting to the
37 server. By default this is either localhost if one of the
38 servers is localhost, or is set to the string returned by
39 info hostname.
40
41 -queue Indicates that the SMTP server should be asked to queue
42 the message for later processing. A boolean value.
43
44 -atleastone
45 Indicates that the SMTP server must find at least one
46 recipient acceptable for the message to be sent. A bool‐
47 ean value.
48
49 -originator
50 A string containing an 822-style address specification.
51 If present the header isn't examined for an originator
52 address.
53
54 -recipients
55 A string containing one or more 822-style address speci‐
56 fications. If present the header isn't examined for
57 recipient addresses). If the string contains more than
58 one address they will be separated by commas.
59
60 -header
61 A list containing two elements, an smtp header and its
62 associated value (the -header option may occur zero or
63 more times).
64
65 -usetls
66 This package supports the RFC 3207 TLS extension (3) by
67 default provided the tls package is available. You can
68 turn this off with this boolean option.
69
70 -tlspolicy
71 This option lets you specify a command to be called if an
72 error occurs during TLS setup. The command is called with
73 the SMTP code and diagnostic message appended. The com‐
74 mand should return 'secure' or 'insecure' where insecure
75 will cause the package to continue on the unencrypted
76 channel. Returning 'secure' will cause the socket to be
77 closed and the next server in the -servers list to be
78 tried.
79
80 -username
81
82 -password
83 If your SMTP server requires authentication (RFC 2554
84 (4)) before accepting mail you can use -username and
85 -password to provide your authentication details to the
86 server. Currently this package supports DIGEST-MD5, CRAM-
87 MD5, LOGIN and PLAIN authentication methods. The most
88 secure method will be tried first and each method tried
89 in turn until we are either authorized or we run out of
90 methods. Note that if the server permits a TLS connec‐
91 tion, then the authorization will occur after we begin
92 using the secure channel.
93
94 Please also read the section on Authentication, it
95 details the necessary prequisites, i.e. packages needed
96 to support these options and authentication.
97
98 If the -originator option is not present, the originator address is
99 taken from From (or Resent-From); similarly, if the -recipients option
100 is not present, recipient addresses are taken from To, cc, and Bcc (or
101 Resent-To, and so on). Note that the header key/values supplied by the
102 -header option (not those present in the MIME part) are consulted.
103 Regardless, header key/values are added to the outgoing message as nec‐
104 essary to ensure that a valid 822-style message is sent.
105
106 The command returns a list indicating which recipients were unaccept‐
107 able to the SMTP server. Each element of the list is another list, con‐
108 taining the address, an SMTP error code, and a textual diagnostic.
109 Depending on the -atleastone option and the intended recipients, a non-
110 empty list may still indicate that the message was accepted by the
111 server.
112
114 Beware. SMTP authentication uses SASL. I.e. if the user has to authen‐
115 ticate a connection, i.e. use the options -user and -password (see
116 above) it is necessary to have the sasl package available so that smtp
117 can load it.
118
119 This is a soft dependency because not everybody requires authentica‐
120 tion, and sasl depends on a lot of the cryptographic (secure) hashes,
121 i.e. all of md5, otp, md4, sha1, and ripemd160.
122
124 proc send_simple_message {recipient email_server subject body} {
125 package require smtp
126 package require mime
127
128 set token [mime::initialize -canonical text/plain \\
129 -string $body]
130 mime::setheader $token Subject $subject
131 smtp::sendmessage $token \\
132 -recipients $recipient -servers $email_server
133 mime::finalize $token
134 }
135
136 send_simple_message someone@somewhere.com localhost \\
137 "This is the subject." "This is the message."
138
139
141 This package uses the TLS package to handle the security for https urls
142 and other socket connections.
143
144 Policy decisions like the set of protocols to support and what ciphers
145 to use are not the responsibility of TLS, nor of this package itself
146 however. Such decisions are the responsibility of whichever applica‐
147 tion is using the package, and are likely influenced by the set of
148 servers the application will talk to as well.
149
150 For example, in light of the recent POODLE attack [http://googleonli‐
151 nesecurity.blogspot.co.uk/2014/10/this-poodle-bites-exploiting-
152 ssl-30.html] discovered by Google many servers will disable support for
153 the SSLv3 protocol. To handle this change the applications using TLS
154 must be patched, and not this package, nor TLS itself. Such a patch
155 may be as simple as generally activating tls1 support, as shown in the
156 example below.
157
158
159 package require tls
160 tls::init -tls1 1 ;# forcibly activate support for the TLS1 protocol
161
162 ... your own application code ...
163
164
166 [1] Jonathan B. Postel, "SIMPLE MAIL TRANSFER PROTOCOL", RFC 821,
167 August 1982. (http://www.rfc-editor.org/rfc/rfc821.txt)
168
169 [2] J. Klensin, "Simple Mail Transfer Protocol", RFC 2821, April
170 2001. (http://www.rfc-editor.org/rfc/rfc2821.txt)
171
172 [3] P. Hoffman, "SMTP Service Extension for Secure SMTP over Trans‐
173 port Layer Security", RFC 3207, February 2002. (http://www.rfc-
174 editor.org/rfc/rfc3207.txt)
175
176 [4] J. Myers, "SMTP Service Extension for Authentication", RFC 2554,
177 March 1999. (http://www.rfc-editor.org/rfc/rfc2554.txt)
178
180 This document, and the package it describes, will undoubtedly contain
181 bugs and other problems. Please report such in the category smtp of
182 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
183 also report any ideas for enhancements you may have for either package
184 and/or documentation.
185
186 When proposing code changes, please provide unified diffs, i.e the out‐
187 put of diff -u.
188
189 Note further that attachments are strongly preferred over inlined
190 patches. Attachments can be made by going to the Edit form of the
191 ticket immediately after its creation, and then using the left-most
192 button in the secondary navigation bar.
193
195 ftp, http, mime, pop3
196
198 email, internet, mail, mime, net, rfc 2554, rfc 2821, rfc 3207, rfc
199 821, rfc 822, smtp, tls
200
202 Networking
203
205 Copyright (c) 1999-2000 Marshall T. Rose and others
206
207
208
209
210tcllib 1.4.5 smtp(n)