You are looking at historical revision 13621 of this page. It may differ significantly from its current revision.
Send e-mails using the SMTP protocol (RFC821).
Errors triggered by invalid or negative replies from the SMTP server are signalled by raising a compund condition of the kinds exn and smtp. The error code of a smtp condition can be accessed with the code property.[procedure] (smtp:connect HOSTNAME DOMAINNAME [VERBOSE [PORT]])
Connects to the server HOSTNAME using the SMTP protocol and identifies this client with DOMAINNAME. If the optional argument VERBOSE is given and not #f, then a protocol of the communication with the server is written to the value of (current-error-port). PORT specifies the port-number and defaults to 25.
This procedure returns an object representing the SMTP session.[procedure] (smtp:disconnect SMTP)
Closes the connection identified by the session object SMTP.[procedure] (smtp:smtp? X)
Returns #t if X is an SMTP session object, or #f otherwise.[procedure] (smtp:open SMTP FROM TO1 TO2...)
Creates a message, where FROM and TO1 TO2... are strings representing the addresses of the sender and the receiver(s), respectively. This procedure returns an output-port that accepts text which is stored as the body of the message. Note that no default headers (other than "From:" and "Date:") are generated. Normally all headers (like "Subject:", etc.) are written first, followed by a completely blank line, followed by the body of the message.
It is not possible to call smtp:open before the port returned by a previously invoked call has been closed.
(define s (smtp:connect "smtp.your-isp.net" (get-host-name))) (define p (smtp:open s "firstname.lastname@example.org" "email@example.com")) (display "Subject: How are you?\r\n\r\nSo, how are you then?\r\n\n" p) (close-output-port p) (smtp:disconnect s)
- 1.3 Uses flush-output after sending message [Thanks to Daishi Kato]
- 1.2 Bugfix by Hans Bulfone
- 1.1 Fixed bug that replaced all occurrences of "." in SMTP headers with ".."
- 1.0 Initial release
Copyright (c) 2003-2008, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.