[Top][All Lists]

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

multiple gmail accounts: smtp and expiry

From: George McNinch
Subject: multiple gmail accounts: smtp and expiry
Date: Sat, 14 Apr 2012 13:36:32 -0400
User-agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.1.50 (gnu/linux)


To the extent that this is useful, I thought I'd share some
idea(s)/solution(s) to issues related to smtp and expiry for multiple
gmail accounts in gnus.

* expiry

I want expired mail from a gmail account to expire to the "correct"
[GMail]/Trash folder(s) for the account.  After some pondering, the
following seems to work. I'd be interested in alternate suggestions,

Suppose that I have two gnus imap groups corresponding to gmail


Use the following to create the per-group "expiry targets".

 (setq gm-gmail1-expiry-targets
       (list (from ".*" "nnimap+gmail1:[Gmail]/Trash"))
 (setq gm-gmail2-expiry-targets
       (list (from ".*" "nnimap+gmail2:[Gmail]/Trash"))
 (defun gm-gmail1-expiry-target-function (group)
   (setq nnmail-fancy-expiry-targets gm-gmail1-expiry-targets)
   (nnmail-fancy-expiry-target group))

 (defun gm-gmail2-expiry-target-function (group)
   (setq nnmail-fancy-expiry-targets gm-gmail2-expiry-targets)
   (nnmail-fancy-expiry-target group))

Now use gnus-parameters (or group parameters, or topic parameters)
to connect the expiry functions:

 (setq gnus-parameters
     (expiry-target . gm-gmail1-expiry-target-function)
     (expiry-target . gm-gmail2-expiry-target-function)

I guess my feeling is that it might be better (??!) if
nnmail-fancy-expiry-target(s) could also qualify expiry targets based on
the value of group, rather than just based data found in the header of
the article. But this might be unwieldy for reasons I haven't thought
of...and anyhow the above seems to do the job.

* smtp

I wanted to be able to adjust the smtp-user via gnus-posting-styles --
e.g. so that "sent" mail automatically ends up in the 


folder of the correct gmail account.

One solution is to adapt some code found here

as follows.

(eval-after-load "smtpmail"
     (defun smtpmail-get-and-delete-smtp-user-from-header ()
       "Find header field X-SMTP-User and if found return value as
         string and delete header field. If a header field of this
         name doesn't exist, return nil."
         (goto-char (point-min))
           (let ((smtp-server))
             (loop until (or (eobp) (looking-at "^[ \t]*$"))
                   if (looking-at "X-SMTP-User[ \t]*:[ \t]*\\(.*?\\)[ \t]*\n")
                   return (prog1 (match-string 1) (replace-match ""))
                   do (forward-line 1))))))
     (defadvice smtpmail-via-smtp (around set-smtp-user-from-header activate)
       (let ((smtpmail-smtp-user (or 


Now just do something like

(setq gnus-posting-styles
      ("X-SMTP-User" "gmail1-user")
      ("X-SMTP-User" "gmail2-user")

(or add the relevant lines to existing defn of gnus-posting-styles...)
to insert "X-SMTP-User" headers temporarily in the mail for consumption by
smtpmail-via-smtp when sending the mail.


  | George McNinch <gmcninch (at)>

reply via email to

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