BruceBlog

Saturday, November 28, 2009

Sending Mail using Gnus and Emacs
(This turned out to be the first post in a series, so read the next few posts if you find this info helpful.)

Well, this post won't look like much, but I'm sending it from emacs using gnus from MS Windows XP. I've spent too much time getting this process to work, with hopes of making it part of an org-based reminder system.

Superficially, here's how I'm sending the email from emacs:

1) Use the command gnus-msg-mail
2) Fill in the To:, Subject:, and the body of this post
3) Hit Ctl-c, Ctl-c to send.

When I send the message, it is going to route through an msmtp SMTP mail client (see http://sourceforge.net/projects/msmtp/). The msmtp program will send it to gmail SMTP server (there's nothing magic about using gmail - it's the one I got to work first). Then the gmail SMTP server sends it on to my blogger account address, where it will automatically
post.

The hard part is getting the internal configuration right. I went down one, maybe two dead ends before discovering this setup. The deadends I got stuck on used the emacs message-mail (a mail mode that comes with Gnus) and mail-compose (an emacs mail system). I tried configuring
smtpmail in emacs to interface to GMail with SMTP and tls authentication and failed several different ways. Finally, I discovered the msmtp process, which I'll outline here.

Here's how to set things up:

1) Download msmtp, unpack it, and put it somewhere (I put it in C:\Program Files\gnu\msmtp).

2) Create a .gnus.el file in your emacs home directory (where .emacs is), with these contents, making appropriate substitutions for account details:

(The following is based on this post on the EmacsWiki.)

;;;;; Start File Contents

;; with Emacs 23.1, you have to set this explicitly (in MS Windows)
;; otherwise it tries to send through OS associated mail client
(setq message-send-mail-function 'message-send-mail-with-sendmail)
;; we substitute sendmail with msmtp
(setq sendmail-program "C:/Program Files/gnu/msmtp/msmtp.exe")
;;need to tell msmtp which account we're using. If your email is
;; user@gmail.com, then the following line works:
(setq message-sendmail-extra-arguments '("-a" "user"))
;; you might want to set the following too
(setq mail-host-address "gmail.com")
(setq user-full-name "Your Name")
(setq user-mail-address "user@gmail.com")

;;;;; End File Contents

3) Gnus is supposed to load the .gnus.el file when it starts up, but it
hasn't for me, so add this line to .emacs:

(load-file ".gnus.el")

4) Create an msmtprc.txt file to configure msmtrp. The file goes in your HOME folder, which is where the .emacs file is. The contents of this file should be as follows (substituting your username and password appropriately):

######## Start File Contents

########################
account default
host smtp.gmail.com
tls on
tls_certcheck off
auth on
user yourname@gmail.com
password yourpassword
port 587
from your_return@address

logfile ~/msmtplog.txt

######## End File Contents

The logfile may not be needed - it shows what mail has been sent. I'm happy to say I don't know what it holds if sending mail fails.

5) Once all the files have been created and saved, exit and restart emacs to make sure everything loads properly. Then use gnus-msg-mail to send a test message. Good luck!

Note: I suspect I can configure Emacs mail to use the msmtprc program without using the Gnus mail system, which is a touch of extra overhead. Maybe I'll try that, but right now I'm happy things work.

Later - it works, so see my next post for how to skip the Gnus mail system.


1 Comments:

  • At 3/19/2010 10:48 AM, Anonymous ignacio said…

    Many thanks for this clear explanation! I was able to set it up this time in my Windows Xp with your advice, something I attempted without success a couple of times before.

     

Post a Comment

<< Home