Skip to content

Instantly share code, notes, and snippets.

@AyeGill
Created December 5, 2012 16:50
Show Gist options
  • Save AyeGill/4217345 to your computer and use it in GitHub Desktop.
Save AyeGill/4217345 to your computer and use it in GitHub Desktop.
Common lisp file mailing automation
;;;;Lisp file mailing automation.
;;;;Purpose: send all files in folder(recursively) by supplied email acount to supplied email account.
;;;;Requires quicklisp. Feel free to make a quicklisp-independent version.
;;;example usage:
;;;(mail-dir "directory" "example@gmail.com" "pass123" :predicate (lambda (x) (not (search "nope"))))
;;;mails all files in directory not containing nope to example@gmail.com, using example@gmail.com with the password pass123
;;Load required stuff.
(ql:quickload "cl-smtp")
(ql:quickload "cl+ssl")
(ql:quickload "cl-fad")
;;Returns a function that sends a specified file to the specified email.
;;Done with partial appliaction because I was thinking too functional programming.
;;recipient defaults to email because I'll mostly be sending shit to myself for backup/to transfer between computers. server defaults to gmail because that's what I use
(defun make-mail-fun (email password &key (recipient email) (server "smtp.gmail.com"))
(lambda (filename)
(cl-smtp:send-email server email recipient (namestring filename) (namestring filename) :authentication `(,email ,password) :ssl :tls :attachments filename)))
;;Like make-email-fun, but works recursively on a directory
;;also optionally takes a predicate, only sends files for which it doesn't return nil.
(defun make-mail-dir-fun (email password &key (recipient email) (server "smtp.gmail.com") (predicate (lambda (x) T)))
(lambda (dirname)
(cl-fad:walk-directory dirname (make-mail-fun email password :recipient recipient :server server) :test predicate)))
;;macro to make using these things less fugly
(defmacro mail-dir (dir &rest emailargs)
`(funcall (make-mail-dir-fun ,@emailargs) ,dir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment