makemime.lisp - creates the multipart/alternative MIME message by using Courier MTA's makemime tool and sends it by using sendmail


makemime.lisp is small peace of software that creates the multipart/alternative message by using the Courier MTA's excellent command line tool makemime and sendmail.

This piece of software in RCD Business replaces the need for cl-sendmail or cl-smtp yet it is effective and fast.

This Lisp function, with some adaptations may be used to effectively send the multipart/alternative MIME messages directly from a command line.

We will gladly adapt the software for your needs that you become able to send multipart/alternative MIME messages directly from command line.

The function is very simple and it may be implemented in any other programming language.

;; (ql)
;; (ql:quickload "cl-rfc2047")
;; (load "streamtools")
;; (load "utilities")

(defun makemime-cl-rfc2047 (string email)
  "Verifies if it is Yahoo email address, attempts not to use UTF-8
for name encoding for Yahoo as their server does not support it."
  (let ((match (search "@yahoo" email)))
    ;; This does now basically the same as if we use "B" encoding, it will not
    ;; work with Yahoo
    (if match (cl-rfc2047:encode string :encoding :q) (cl-rfc2047:encode string :encoding :q))))

(defun makemime-send (text html &key from-name from-email to-name to-email subject)
  "Creates multipart/alternative MIME message and sends it by using sendmail"
  (let* ((text-file "/dev/shm/text-file")
         (html-file "/dev/shm/html-file")
         (text-file (progn
                      (string-to-file :string text :file text-file)
         (html-file (progn
                      (string-to-file :string html :file html-file)
         (makemime-file "/dev/shm/makemime")
         (makemime-set (string-to-file :string (format nil "-j
Mime-Version: 1.0
From: ~A <~A>
To: ~A <~A>
Subject: ~A
Content-Disposition: inline
-C utf-8
-c text/plain
-C utf-8
-c text/html
-C utf-8
" (makemime-cl-rfc2047 from-name to-email) from-email
  (makemime-cl-rfc2047 to-name to-email) to-email
  (makemime-cl-rfc2047 subject to-email) text-file html-file) :file makemime-file))
     (makemime (slurp-stream-io-command "makemime @-" makemime-set))
     (sendmail (format nil "/usr/bin/env TO-NAME=\"~A\" TO-EMAIL=\"~A\" /usr/local/bin/sendmail -F \"~A\" -f ~A" to-name to-email from-name from-email)))
    (multiple-value-bind (output error status)
        (string-to-command sendmail makemime)
      (declare (ignore output error))

(defun send-example ()
  (let ((status 
 "Hello ® UTF-8 ŠđŽ"
 "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional //EN\">
  <meta http-equiv=\"Content-Type\"
        content=\"text/html; charset=utf-8\">  <title></title>
<h2>Hello there</h2>


<p>This is some text here. č</p>
 :from-name "Jean"
 :from-email ""
 :to-name "Jean Louis"
 :to-email ""
 ;;:to-email ""
 :subject "Testing čekaj" ))) ;; #$%&/(`°=˝?'*+÷פß") ))

;; (send-example)

Leave Your Comment or Contact GNU.Support

Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know

Full name: