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 "alexandria")
;; (ql:quickload "cl-rfc2047")

(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
                      (alexandria:write-string-into-file text text-file :if-does-not-exist :create :if-exists :supersede)
                     text-file))
         (html-file (progn
                      (alexandria:write-string-into-file html html-file :if-does-not-exist :create :if-exists :supersede)
                     html-file))
         (makemime-file "/dev/shm/makemime")
         (makemime-set (alexandria:write-string-into-file (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
)
" (cl-rfc2047:encode from-name) from-email
  (cl-rfc2047:encode to-name) to-email
  subject text-file html-file) makemime-file :if-exists :supersede :if-does-not-exist :create))
    (makemime (slurp-stream-io-command "makemime @-" makemime-set))
    (sendmail (format nil "/usr/bin/env TO-NAME=\"~a\" TO-EMAIL=\"~a\" /usr/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)))

;; (send-example)

(defun send-example ()
  (let ((status 
  (makemime-send
 "Hello ® UTF-8 ŠđŽ"
 "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional //EN\">
<html>
<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 "Mr. From"
 :from-email "admin@example.com"
 :to-name "Mr. Who"
 :to-email "admin@example.com"
 :subject " #$%&/(`°=˝?'*+÷פß") ))
    status))

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:


"/>