使用Clojure和apache.commons.MultiPartEmail:邮件可以通过,但没有附件

使用Clojure和apache.commons.MultiPartEmail:邮件可以通过,但没有附件,clojure,email-attachments,Clojure,Email Attachments,我正在尝试使用以下代码从Clojure发送电子邮件: 发送电子邮件的助手功能: (defn- send [recipient from subject msg host content-type & attachments] (let [att-ds (map (fn [at] {:ds (ByteArrayDataSource. (:source at) (:type a

我正在尝试使用以下代码从Clojure发送电子邮件:

发送电子邮件的助手功能:

(defn- send [recipient from subject msg host content-type & attachments]
  (let [att-ds (map (fn [at] {:ds (ByteArrayDataSource. (:source at)
                                                        (:type at))
                              :name (:name at)
                              :description (:description at)})
                    attachments)
        mpmail (MultiPartEmail.)]
    (doto mpmail
      (.setHostName host)
      (.setFrom from)
      (.setSubject subject)
      (.setContent msg content-type)
      (.setCharset "utf-8"))
    (.addTo mpmail recipient)
    (doseq [ds att-ds]
      (.attach mpmail (:ds ds) (:name ds) (:description ds)))
    (.send mpmail)))
用法:

(send "sender@my.domain" 
      "recipient@my.domain" 
      "SUBJECT"
      "MSG"
      "my.smtp.server"
      "text/plain"
      {:source (.getBytes "Attachment") 
      :type "text/plain"
      :name "test.txt"
      :description "test"})
从REPL(或从我的应用程序)运行上述操作将导致recipient@my.domain接收主题为“subject”且正文为“MSG”但没有任何附件痕迹的电子邮件。任何地方都没有例外

我已经在两个不同的smtp服务器上尝试过了


谢谢您的帮助。

尝试将
(.setContent msg)
替换为
(.setMsg)
。可能是当您调用
setContent
时,它认为您手动设置了内容,而忽略了以下
attach
方法。

尝试使用我的代码片段

附件文件名可以是unicode格式