Common Lisp Package: CL-SMTP

README:

FUNCTION

Public

Undocumented

MAKE-ATTACHMENT (DATA-PATHNAME &KEY (NAME (FILE-NAMESTRING DATA-PATHNAME)) (MIME-TYPE (LOOKUP-MIME-TYPE NAME)))

RFC2045-Q-ENCODE-STRING (STR &KEY (EXTERNAL-FORMAT UTF-8))

RFC2231-ENCODE-STRING (STRING &KEY (EXTERNAL-FORMAT UTF-8))

SEND-EMAIL (HOST FROM TO SUBJECT MESSAGE &KEY SSL (PORT (IF (EQ TLS SSL) 465 25)) CC BCC REPLY-TO EXTRA-HEADERS HTML-MESSAGE DISPLAY-NAME AUTHENTICATION ATTACHMENTS (BUFFER-SIZE 256) (EXTERNAL-FORMAT UTF-8))

Private

BASE64-ENCODE-FILE (FILE-IN SOCK &KEY (BUFFER-SIZE 256) (WRAP-AT-COLUMN 70))

Encodes the file contents given by file-in, which can be of any form appropriate to with-open-file, and write the base-64 encoded version to sock, which is a socket. Buffer-size, given in KB, controls how much of the file is processed and written to the socket at one time. A buffer-size of 0, processes the file all at once, regardless of its size. One will have to weigh the speed vs, memory consuption risks when chosing which way is best. Wrap-at-column controls where the encode string is divided for line breaks.

FINISH-SMTP-MAIL (STREAM)

Finish sending an email to the SMTP server connected to on STREAM. The server is expected to be inside of the DATA SMTP command. The connection is then terminated by sending a QUIT command.

INITIATE-SMTP-MAIL (STREAM FROM TO)

Initiate an SMTP MAIL command, sending a MAIL FROM command for the email address in FROM and RCPT commands for all receipients in TO, which is expected to be a list. If any of the TO addresses is not accepted, a RCPT-FAILED condition is signalled. This condition may be handled by the caller in order to send the email anyway.

LOOKUP-MIME-TYPE (FILE-NAME &OPTIONAL (DEFAULT application/octet-stream))

Extract mime type based on file-extension

MASK-DOT (STR)

Replace all occurences of rn.rn in STR with rn..rn

SEND-MAIL-HEADERS (STREAM &KEY FROM TO CC REPLY-TO EXTRA-HEADERS DISPLAY-NAME SUBJECT (EXTERNAL-FORMAT UTF-8))

Send email headers according to the given arguments to the SMTP server connected to on STREAM. The server is expected to have previously accepted the DATA SMTP command.

SMTP-AUTHENTICATE (STREAM AUTHENTICATION FEATURES)

Authenticate to the SMTP server connected on STREAM. AUTHENTICATION is a list of two or three elements. If the first element is a keyword, it specifies the desired authentication method (:PLAIN or :LOGIN), which is currently ignored. The actual method used is determined by looking at the advertised features of the SMTP server. The (other) two elements of the AUTHENTICATION list are the login username and password. FEATURES is the list of features announced by the SMTP server. If the server does not announce any compatible authentication scheme, the NO-SUPPORTED-AUTHENTICATION-METHOD error is signalled.

SMTP-HANDSHAKE (STREAM &KEY AUTHENTICATION SSL LOCAL-HOSTNAME)

Perform the initial SMTP handshake on STREAM. Returns the stream to use further down in the conversation, which may be different from the original stream if we switched to SSL.

SUBSTITUTE-RETURN-NEWLINE (STR)

Replace all occurences of rn in STR with spaces

Undocumented

CHECK-ARG (ARG NAME)

DO-WITH-SMTP-MAIL (HOST FROM TO THUNK &KEY PORT AUTHENTICATION SSL LOCAL-HOSTNAME (EXTERNAL-FORMAT UTF-8))

ESCAPE-RFC822-QUOTED-STRING (STR)

GENERATE-MESSAGE-HEADER (SOCK &KEY BOUNDARY CONTENT-TYPE CONTENT-DISPOSITION CONTENT-TRANSFER-ENCODING (INCLUDE-BLANK-LINE? T))

GENERATE-MULTIPART-HEADER (SOCK BOUNDARY &KEY (MULTIPART-TYPE mixed))

GET-COMPONENT-PATHNAME

GET-EMAIL-DATE-STRING

GET-TIMEZONE-FROM-INTEGER (X)

MAKE-RANDOM-BOUNDARY (&OPTIONAL (LENGTH 30) (BOUNDARY-CHARS *BOUNDARY-CHARS*))

READ-FROM-SMTP (STREAM &OPTIONAL LINES)

RUN-TEST (NAME)

RUN-TESTS

SEND-ATTACHMENT (SOCK ATTACHMENT BOUNDARY BUFFER-SIZE EXTERNAL-FORMAT)

SEND-ATTACHMENT-HEADER (SOCK BOUNDARY ATTACHMENT EXTERNAL-FORMAT)

SEND-END-MARKER (SOCK BOUNDARY)

SEND-MULTIPART-HEADERS (STREAM &KEY ATTACHMENT-BOUNDARY HTML-BOUNDARY)

SEND-SMTP (HOST FROM TO SUBJECT MESSAGE &KEY SSL (PORT (IF (EQ TLS SSL) 465 25)) CC BCC REPLY-TO EXTRA-HEADERS HTML-MESSAGE DISPLAY-NAME AUTHENTICATION ATTACHMENTS BUFFER-SIZE (LOCAL-HOSTNAME (GET-HOST-NAME)) (EXTERNAL-FORMAT UTF-8))

SMTP-COMMAND (STREAM COMMAND EXPECTED-RESPONSE-CODE &KEY (CONDITION-CLASS 'SMTP-PROTOCOL-ERROR) CONDITION-ARGUMENTS)

STRING-TO-BASE64-STRING (STR)

WRITE-BLANK-LINE (STREAM)

WRITE-TO-SMTP (STREAM COMMAND)

MACRO

Public

WITH-SMTP-MAIL ((STREAM-VAR HOST FROM TO &KEY SSL (PORT (IF (EQ TLS SSL) 465 25)) AUTHENTICATION LOCAL-HOSTNAME (EXTERNAL-FORMAT UTF-8)) &BODY BODY)

Encapsulate a SMTP MAIl conversation. A connection to the SMTP server on HOST and PORT is established and a MAIL command is initiated with FROM being the mail sender and TO being the list of recipients. BODY is evaluated with STREAM-VAR being the stream connected to the remote SMTP server. BODY is expected to write the RFC2821 message (headers and body) to STREAM-VAR.

Private

Undocumented

DEFINE-CL-SMTP-TEST (NAME (&REST ARGS) &BODY BODY)

GENERIC-FUNCTION

Private

Undocumented

COMMAND (CONDITION)

EXPECTED-RESPONSE-CODE (CONDITION)

FEATURES (CONDITION)

RECIPIENT (CONDITION)

RESPONSE-CODE (CONDITION)

RESPONSE-MESSAGE (CONDITION)

SLOT-ACCESSOR

Public

Undocumented

ATTACHMENT-DATA-PATHNAME (OBJECT)

SETFATTACHMENT-DATA-PATHNAME (NEW-VALUE OBJECT)

ATTACHMENT-MIME-TYPE (OBJECT)

SETFATTACHMENT-MIME-TYPE (NEW-VALUE OBJECT)

ATTACHMENT-NAME (OBJECT)

SETFATTACHMENT-NAME (NEW-VALUE OBJECT)

VARIABLE

Private

Undocumented

*BOUNDARY-CHARS*

*CL-SMTP-TESTS*

*DEBUG*

*LINE-WITH-ONE-DOT*

*LINE-WITH-TWO-DOTS*

*MIME-TYPE-DESCRIPTIONS*

*MIME-TYPES*

*RETURN-NEWLINE*

*X-MAILER*

CLASS

Public

Undocumented

ATTACHMENT

CONDITION

Public

Undocumented

NO-SUPPORTED-AUTHENTICATION-METHOD

RCPT-FAILED

SMTP-ERROR

SMTP-PROTOCOL-ERROR