|Allegro CL version 8.2|
Unrevised from 8.1 to 8.2.
Arguments: mail-server from to &rest message
This function requests that a SMTP server send a message. The return value of this function is undefined. If this function returns rather than signaling an error, then it has "succeeded", where "success" means the SMTP server claimed that it received the message.
mail-server specifies the mail server and also additional information. It can specify the port number, details of an SSL connection, and whether to initiate STARTTLS negotiations. The value of the argument can be a string or an IP address (to specify just a server or a server and a port number), a cons (to specify a server and a port number) or a list (to provide value for all options). See below for details.
If the server specified by mail-server requires authentication, you should use send-smtp-auth, which works just like this function but has additional required arguments login and password.
The mail-server is contacted and asked to send a message (a string) from the email address specified by from to the email address or list of addresses specified by to. The email addresses must be of the form "foo" or "email@example.com". You can not use addresses like "Joe <firstname.lastname@example.org>" or "(Joe) email@example.com".
The message sent is a concatenation of all of the
message arguments (there can be as many as
you like). messages should be strings or streams
in any combination. (message cannot be
though see MIME messages below.) When a message is a stream,
note the stream is read until an EOF is reached, but the stream is not
closed nor is the file pointer reset.
A header is not prepended to the message. This means that the application program can build its own header if it wants to include in that header more than send-letter supports (e.g. a Mime encoded attachment). If no header is provided then some mail servers (e.g. sendmail) will notice this fact and will automatically create a header.
The text of the message should be lines separated by #\newline's. The smtp interface will automatically insert the necessary #\returns's when it transmits the message to the mail server.
As said above, message cannot be a
object (see MIME support in
imap.htm) but you can do something like this:
(setf p1 (make-mime-part :text "This is a test message" :headers '(("From" . "Test User <firstname.lastname@example.org>") ("To" . "Recipient <email@example.com>") ("Subject" . "This is a test email")))) (with-mime-part-constructed-stream (s p1) (send-smtp mail-server "firstname.lastname@example.org" "email@example.com" s))
The mail-server argument serves several functions. In all cases, it specifies the mail server. It can also specify a port number. And it can specify SSL and STARTTLS details. We discuss each use in turn.
The value can be a string naming a machine, or an IP address (in dotted form, as an integer for IPv4 addresses, or an IPv6 address structure).
By default, this function makes a connection to port 25 on mail-server.
If you need to connect to a port other than the default (port 25), you can specify the mail-server argument in one of the following two ways to specify the alternate port number (and, as described below, an alternate port can be specified along with SSL and STARTTLS information):
'("smtp.example.com" . 99)and port 99 will be used.
"smtp.example.com:99". Note that this form is not suitable if the mail server is specified as an IPv6 dotted address (because the dotted address uses colons as separators).
The most general form of the mail-server argument is a list of the form:
(server-name &key (port 25) (ssl nil) (starttls nil) ...ssl-client-keywords...)
nil, the default port is 465.
nil, make-ssl-client-stream will be called after establishing a connection to the smtp server. All ssl-client-keywords are passed to make-ssl-client-stream as well.
nil, it allows for negotiation of a secure connection (TLSv1) if the server supports it. If the server supports both auth and starttls, starttls will be negotiated before attempting authentication.
No error is signalled if both ssl
and starttls are
nil. The SSL connection is established
before any starttls negotiation would begin.
(use-package :net.post-office) (defparameter *smtp-host* "localhost") (defparameter *smtp-user* "someuser") (defparameter *smtp-password* "somepassword") ;; ssl with authentication (let ((part (make-mime-part :text "This is a test message sent via Secure smtp server with authentication." :headers '(("From" . "Test User <firstname.lastname@example.org>") ("To" . "Recipient <email@example.com>") ("Subject" . "This is a test email"))))) (with-mime-part-constructed-stream (s part) (send-smtp-auth (list *smtp-host* :ssl t :method :sslv3+) *smtp-user* "firstname.lastname@example.org" *smtp-user* *smtp-password* s))) ;; with starttls negotiation (let ((part (make-mime-part :text "This is a test message sent possibly via a TLSv1 encrypted channel." :headers '(("From" . "Test User <email@example.com>") ("To" . "Recipient <firstname.lastname@example.org>") ("Subject" . "This is a test email"))))) (with-mime-part-constructed-stream (s part) (send-smtp (list *smtp-host* :starttls t) *smtp-user* "email@example.com" s)))
See imap.htm for more information.
Copyright (c) 1998-2012, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 8.2. This page was not revised from the 8.1 page.
|Allegro CL version 8.2|
Unrevised from 8.1 to 8.2.