Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Monday, January 14, 2008

Emacs Tip #10: sig-quote (intelligent, random signatures)

Way back when I first started using Emacs, I read email with it. A friend had some script which modified his .signature file with a random quote every 30 seconds. I thought that was kind of neat, but I wanted every email to get its own, random, quote. At the time I didn't know how to get a random number in a simple shell script, so I started writing something using Emacs directly.

A random signature wasn't enough though, I then wanted to be able to have different categories of quotes and send different people quotes from those different categories. From the documentation:


;; This mode is designed to allow a user to have quotes appended to
;; their mail and news posts according to whom/where the mail is
;; being sent. For example, one might wish to have "insightful"
;; quotes sent to Prof. Apple, and "crude" quotes to your brother
;; Sam. With this mode, upon sending a piece of mail, the email
;; addresses are scanned (this includes the To:, CC:, and BCC:
;; headers), and an appropriate quote is inserted into the letter.


Thus began my Emacs fascination.

You can download the source here.

Thursday, January 10, 2008

Emacs Tip #9: Gnus/Gmail integration (using IMAP)

Like many folks, I use Google for more and more. When I noticed Google's announcement that Gmail supports IMAP, I knew I could read my Gmail from Emacs.

The question was, how do you set up the integration? The Emacs wiki had instructions on how to read email, which worked nicely. But I wanted to enable Gmail to gather the mail I sent from Emacs into its conversation groups (it's no Gnus threading, but it's a start). So how to enable that? At first I automatically Bcc'ed my Gmail account, but that was hacky. Then I noticed Gmail lets you use their SMTP server.

I found some documentation on how to use it, but it didn't work for me (wrong ports evidentially), and it was integrated differently than what I wanted.

So I used my favorite Emacs lisp feature, advice, and wrote the following snippet. It checks to see if the 'From:' address is a gmail address, in which case it uses Gmail's SMTP server.


(defadvice message-send-mail (around gmail-message-send-mail protect activate)
"Set up SMTP settings to use Gmail's server when mail is from a gmail.com address."
(interactive "P")
(if (save-restriction
(message-narrow-to-headers)
(string-match "gmail.com" (message-fetch-field "from")))

(let ((message-send-mail-function 'smtpmail-send-it)
;; gmail says use port 465 or 587, but 25 works and those don't, go figure
(smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil)))
(smtpmail-auth-credentials '(("smtp.gmail.com" 25 "username@gmail.com" nil)))
(smtpmail-default-smtp-server "smtp.gmail.com")
(smtpmail-smtp-server "smtp.gmail.com")
(smtpmail-smtp-service 25)
(smtpmail-local-domain "yourdomain.com"))
ad-do-it)
ad-do-it))

Note: You can also download the snippet directly.

And, as a good netizen, I updated the wiki appropriately.

Friday, January 4, 2008

Emacs Tip #8 : markdown

I saw a post for auto-generating HTML and thought, neat trick. My preferred email client is Gnus, which already mimics that (changing *text* into text and so forth).

But how cool would it be to have both my regular text show up, as well as an HTML version (when useful) - I already write using the syntax of markdown.

Mr. O'Connor happened to choose to do integration using Python (preferred programming language). Of course I don't grok Python, so getting it to work isn't quite as easy as running the Perl version.

So I coded up similar functionality, only I also tweaked things such that only the text before the signature line is converted into HTML.


(defun mimedown ()
(interactive)
(save-excursion
(message-goto-body)
(let* ((sig-point (save-excursion (message-goto-signature) (forward-line -1) (point)))
(orig-txt (buffer-substring-no-properties (point) sig-point)))
(shell-command-on-region (point) sig-point "Markdown.pl" nil t)
(insert "<#multipart type=alternative>\n")
(insert orig-txt)
(insert "<#part type=text/html>\n< html>\n< head>\n< title> HTML version of email</title>\n</head>\n< body>")
(exchange-point-and-mark)
(insert "\n</body>\n</html>\n<#/multipart>\n"))))