emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more on starttls, gnutls-cli and using tls for mail


From: Vijay Lakshminarayanan
Subject: Re: more on starttls, gnutls-cli and using tls for mail
Date: Sun, 14 Aug 2011 17:32:39 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (windows-nt)

Karl Fogel <address@hidden> writes:

> Leo <address@hidden> writes:
>>I use smtpmail-auth-credentials to pass different user names for the
>>gmail smtps I am using. With the new smtpmail.el I haven't found a way
>>to do that.
>
> Yes, I'm in that situation too now -- which is why I think it's so
> unfortunate that `smtpmail-auth-credentials' went away :-(.
>
> I've found a way to do it, using the new smtpmail.el, but it's ugly.
> I have `message-send-hook' set up ~/.authinfo for every mail message,
> and then I remove the file afterwards in `message-sent-hook'.  Search
> for "kf-set-up-authinfo" in [1] if you want the code.
>
> Naturally I hope we'll restore the lost functionality to smtpmail.el, so
> this kluge will become unnecessary!  The ideal behavior, I think, would
> be to pay attention to ~/.authinfo when it is present, but fall back to
> trying `smtpmail-auth-credentials' when it's not.

I have multiple GMail accounts and I use a hook to use the correct
authentication depending upon which account I'm using.

The hook function is

(defun change-smtp ()
  "Change the SMTP server according to the current from line."
  (save-excursion
    (let* ((username-fn
            (lambda (from)
              (when (string-match "\\<\\([A-Za-z.]*\\)@" from)
                (setq from (match-string 1 from))
                ;; Gmail addresses can have dots in them, so sending
                ;; an email to address@hidden or address@hidden
                ;; will go to the same destination.  So credentials
                ;; for both addresses are stored under the symbol
                ;; `abcd'.
                (setq from (replace-regexp-in-string "\\." "" from))
                (intern from))))
           (from (save-restriction
                   (message-narrow-to-headers)
                   (message-fetch-field "from")))
           (username (funcall username-fn from))
           (credentials (cdr (assoc username *gmail-auth-credentials*))))
      (if credentials
          (setq smtpmail-starttls-credentials credentials
                smtpmail-auth-credentials credentials)
        (error "Could not find auth credentials for %s" from)))))

(add-hook 'message-send-hook 'change-smtp)

where the variable *gmail-auth-credentials* maintains all my user
account info as an alist in the form:

((account1 ("smtp.gmail.com" 587 "address@hidden"  "password1"))
 (account2 ("smtp.gmail.com" 587 "address@hidden"  "password2"))
 (account3 ("smtp.gmail.com" 587 "address@hidden"  "password3"))
 (account4 ("smtp.gmail.com" 587 "address@hidden" "password4")))

I save it in a file ~/.gmails.gpg and in my .gnus I have 

(eval-when-compile
  (load "~/.gmails.gpg"))

Takes care of authentication.  Of course, now that this is out, someone
could possibly get my email account information by convincing me to
download their cool emacs package.  But I don't think I'm that important :-)

Hope this code helps someone.  As with other Free Software licenses,
this comes with NO WARRANTY.

> -Karl
>
> [1] http://svn.red-bean.com/repos/kfogel/trunk/.emacs
>

-- 
Cheers
~vijay

Gnus should be more complicated.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]