Here I’ll try to show how to configure Gnus to connect to your gmail account so you can read and send your e-mails without having to leave your Emacs
If you have multiple IMAP accounts I also tell you how to configure Gnus for multiple IMAP account, the same thing can be done for POP accounts, though I don’t mention POP here.
All the stuff here are slightly modified configurations found at the EmacsWiki
Every time you load gnus with the commands M-x gnus or M-x gnus-other-frame it reads the file ~/.gnus, so, all configurations mentioned here should be added to this file.
So, beginning the configuration process let’s configure our Gnus so it can fetch e-mails from your Gmail account:
(setq gnus-select-method ‘(nnimap “gmail”
(nnimap-address “imap.gmail.com”)
(nnimap-server-port 993)
(nnimap-stream ssl)))
This is all you need to start reading your e-mails with Gnus, note that you will have to have gnutls package installed in order to use ssl.
To test this type M-x gnus, it should ask for your login, type yourusername@gmail.com than type your password. After that you should be redirected to the *Group* buffer, type U and subscribe to your Gmail folders. There are lot’s of options, too many to be mentioned here, please read the EmacsWiki for more information.
In order to not have to be typing your account and password you can edit a file called ~/.authinfo and add something like this:
machine imap.gmail.com login myaccount@gmail.com password mypassword port 993
machine smtp.gmail.com login myaccount@gmail.com password mypassword port 587
Change myaccount and mypassword to your account and password. The smtp line will be use for sending mail.
To add another IMAP account use the gnus-secondary-select-methods variable like this:
(setq gnus-secondary-select-methods
‘((nnimap “AnotherAccount”
(nnimap-address “imap.something.com”)
(nnimap-server-port 993)
(nnimap-stream ssl))))
Unfortunately there is no native method to add multiple SMTP servers on Gnus. But after taking a quick look at the wiki I found this link. I changed it a little bit, so the passwords are searched at the ~/.authinfo file instead of being in your .gnus file.
Here is the code found on my .gnus file:
;; Available SMTP accounts.
(defvar smtp-accounts
‘((ssl “mymail@gmail.com” “smtp.gmail.com” 587 “key” nil)
(ssl “mymail@otherserver.com” “smtp.otherserver.com” 25 “key” nil)))
This lists my SMTP accounts, one line for each server, as you can see both the servers are using SSL.
;; Default smtpmail.el configurations.
(require ‘smtpmail)
(setq send-mail-function ‘smtpmail-send-it
message-send-mail-function ‘smtpmail-send-it
mail-from-style nil
user-full-name “Rodrigo S. Wanderley”
user-mail-address “mymail@gmail.com”
message-signature-file “~/emacs/signature”
smtpmail-debug-info t
smtpmail-debug-verb t)
The code above just sets some default values. My mail signature is found on the file ~/emacs/signature, I also specify my user name user-full-name and my e-mail address user-mail-address so that Gnus can fill the From header field automatically for me.
The Debug options is also nice so that you get some feedback about what is happening while Gnus is sending the e-mail for you.
(defun set-smtp-plain (server port)
“Set related SMTP variables for supplied parameters.”
(setq smtpmail-smtp-server server
smtpmail-smtp-service port
smtpmail-auth-credentials “~/.authinfo”
smtpmail-starttls-credentials nil)
(message “Setting SMTP server to `%s:%s’.”
server port address))(defun set-smtp-ssl (server port key cert)
“Set related SMTP and SSL variables for supplied parameters.”
(setq starttls-use-gnutls t
starttls-gnutls-program “gnutls-cli”
starttls-extra-arguments nil
smtpmail-smtp-server server
smtpmail-smtp-service port
smtpmail-starttls-credentials (list (list server port key cert))
smtpmail-auth-credentials “~/.authinfo”)
(message
“Setting SMTP server to `%s:%s’. (SSL enabled.)”
server port address))
Those are two functions used to send mail, one with and one without SSL support. Note that smtpmail-auth-credentials is telling Gnus where to find the username and password.
(defun change-smtp ()
“Change the SMTP server according to the current from line.”
(save-excursion
(loop with from = (save-restriction
(message-narrow-to-headers)
(message-fetch-field “from”))
for (acc-type address . auth-spec) in smtp-accounts
when (string-match address from)
do (cond
((eql acc-type ‘plain)
(return (apply ‘set-smtp-plain auth-spec)))
((eql acc-type ‘ssl)
(return (apply ‘set-smtp-ssl auth-spec)))
(t (error “Unrecognized SMTP account type: `%s’.” acc-type)))
finally (error “Cannot interfere SMTP information.”))))(add-hook ‘message-send-hook ‘change-smtp)
Finally we create a hook for when me message is going to be sent. This hook basically tries to match the From header with the e-mail address you specified at smtp-account variable and chooses the server accordingly.
I tried to follow your directions but they failed. I’ve asked a question on the gnus gmane group documenting my attempt:
http://news.gmane.org/gmane.emacs.gnus.user
An update – you have nnimap-stream as ssl but i think it should be tls, per this post:
http://www.mail-archive.com/info-gnus-english@gnu.org/msg09352.html
Hello, I STFW everywhere for this stuff. I decided to use IMAP to access Gmail from Gnus, and I did exactly as you described here (also the same as emacswiki), but in the server buffer, the entry {nnimap:gmail} always shows (denied). I’m really pissed off… In Mutt everything is fine, also using IMAP. Could you please tell me what’s wrong? I’m just trying to convert to Gnus in favor of mutt, but this is annoying.