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

makemime.lisp

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)
              text-file))
         (html-file (progn
                      (string-to-file :string html :file html-file)
                     html-file))
         (makemime-file "/dev/shm/makemime")
         (makemime-set (string-to-file :string (format nil "-j
(
-m
multipart/alternative
-a
Mime-Version: 1.0
-a
From: ~A <~A>
-a
To: ~A <~A>
-a
Subject: ~A
-a
Content-Disposition: inline
-e
quoted-printable
-C utf-8
(
-c text/plain
-C utf-8
~a
)
)
(
-c text/html
-N HTML
-C utf-8
~A
)
" (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))
      status)))

(defun makemime-construct (from-name from-email to-name to-email subject text-file html-file)
  "Returns makemime construct with text file and html file"
  (let ((makemime-set (format nil "-j
(
-m
multipart/alternative
-a
Mime-Version: 1.0
-a
From: ~A <~A>
-a
To: ~A <~A>
-a
Subject: ~A
-a
Content-Disposition: inline
-e
quoted-printable
-C utf-8
(
-c text/plain
-C utf-8
~a
)
)
(
-c text/html
-N HTML
-C utf-8
~A
)
" (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)))
    (slurp-stream-io-command "makemime @-" makemime-set)))

;; (makemime-construct "Jean Louis" "ss@rcdrun.com" "Jean" "ss@rcdrun.com" "Testing" "/dev/shm/text-file" "/dev/shm/html-file")

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

<p>http://www.google.com</p>

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

;; (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:


E-mail:


Message: