Gnus development mailing list
 help / color / mirror / Atom feed
From: Johnny <yggdrasil@gmx.co.uk>
To: Sivaram Neelakantan <nsivaram.net@gmail.com>
Cc: ding@gnus.org
Subject: Re: Multiple gmail accounts and SMTP (again)
Date: Mon, 25 Jul 2011 21:23:45 +0100	[thread overview]
Message-ID: <87ipqq85ym.fsf@DeuxExMachina.config> (raw)
In-Reply-To: <82livmutrm.fsf@gmail.com> (Sivaram Neelakantan's message of "Mon, 25 Jul 2011 23:28:37 +0530")

Sivaram Neelakantan <nsivaram.net@gmail.com> writes:

> On Mon, Jul 25 2011,Johnny  wrote:
>
>
> [snipped 28 lines]
>
>> (For SMTP, I am using the emacs-wiki setup, as described here:
>> http://www.emacswiki.org/emacs/MultipleSMTPAccounts)
>>
>> I then attempted to use virtual server names for SMTP as well, i.e.:
>> In .gnus.el:
>> (setq smtp-accounts '(
>>                       (ssl "gmail1" "smtp.gmail.com" "587"
>>                             "gmail1@gmail.com" nil)
>>                       (ssl "gmail2" "smtp.gmail.com" "587"
>>                             "gmail2@gmail.com" nil)))

And using the cusomtised sendmail parts from 
 http://www.emacswiki.org/emacs/MultipleSMTPAccounts as:

;; Now lets configure smtpmail.el with your name and functions to send
;; mail using your smtp accounts by changing the from field
(require 'smtpmail)
(setq send-mail-function 'smtpmail-send-it message-send-mail-function
   'smtpmail-send-it mail-from-style nil user-full-name "Your name" smtpmail-debug-info t smtpmail-debug-verb t)

;Update only the smtp-accounts, gnus-posting-styles and the .authinfo.gpg
(defun set-smtp (mech server port user password)
  "Set related SMTP variables for supplied parameters."
  (setq smtpmail-smtp-server server
	smtpmail-default-smtp-server server
        smtpmail-smtp-service port
        smtpmail-auth-credentials (list (list server port user password))
        smtpmail-auth-supported (list mech)
        smtpmail-starttls-credentials nil)
  (message "Setting SMTP server to `%s:%s' for user `%s'."
           server port user))

(defun set-smtp-ssl (server port user password &optional key cert)
  "Set related SMTP and SSL variables for supplied parameters."
  (setq starttls-use-gnutls t
        starttls-gnutls-program "gnutls-cli"
	smtpmail-default-smtp-server server
        ;; TODO: Add this to the server parameters
        ;; starttls-extra-arguments nil
        smtpmail-smtp-server server
        smtpmail-smtp-service port
        smtpmail-auth-credentials (list (list server port user password))
        smtpmail-starttls-credentials (list (list server port key cert)))
  (message
   "Setting SMTP server to `%s:%s' for user `%s'. (SSL enabled.) Key: `%s' Cert: `%s' Pass: `%s'"
   server port user key cert password))

(defun change-smtp ()
  "Change the SMTP server according to the current from line."
  (interactive)
  (save-excursion
    (loop with from = (save-restriction
                        (message-narrow-to-headers)
                        (message-fetch-field "from"))
          for (auth-mech address . auth-spec) in smtp-accounts
          when (string-match address from)
          do (cond
              ((memq auth-mech '(cram-md5 plain login))
               (return (apply 'set-smtp (cons auth-mech auth-spec))))
              ((eql auth-mech 'ssl)
               (return (apply 'set-smtp-ssl auth-spec)))
              (t (error "Unrecognized SMTP auth. mechanism: `%s'." auth-mech)))
          finally (error "Cannot infer SMTP information."))))

(defvar %smtpmail-via-smtp (symbol-function 'smtpmail-via-smtp))

(defun smtpmail-via-smtp (recipient smtpmail-text-buffer)
  (with-current-buffer smtpmail-text-buffer (change-smtp))
     (funcall (symbol-value '%smtpmail-via-smtp) recipient smtpmail-text-buffer))

>>
>> And in authinfo:
>>  machine gmail1 login gmail1@gmail.com password gmail1pass port 587
>>  machine gmail2 login gmail2@gmail.com password gmail2pass port 587
>>
>> This breaks the sendmail/authinfo functionality such that I have to
>> enter credentials every time sending mail from either account.
>>
>> If I instead replace the 2 lines above in authinfo with:
>>  machine smtp.gmail.com login gmail1@gmail.com password gmail1pass port 587
>>
>> This makes mailing from both addresses work. I /think/ the setup makes
>> gmail2 use gmail1's SMTP credentials to send the mail (note that I
>> didn't have to do any changes in .gnus.el on the gmail2 credentials),
>> and indeed, when it is received, the posting-styles for gmail2 is used,
>> but the senders mail address has been changed to gmail1, which I do not
>> fancy at all.
>
> Can you post your customised sendmail parts that you took from 
>  http://www.emacswiki.org/emacs/MultipleSMTPAccounts
I amended the code as it appears in my .gnus.el above.
>
> It's possible that smtp-mail-address is not getting correctly picked up?
Maybe, but I don't know how to debug. I have hacked away on a copy/paste
trial/error basis. Not too academic, but hey, sometimes it works. Alas,
not this time...

cheers

-- 
Johnny



  reply	other threads:[~2011-07-25 20:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-24 20:55 Johnny
2011-07-25 17:58 ` Sivaram Neelakantan
2011-07-25 20:23   ` Johnny [this message]
2011-08-21  4:14 ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ipqq85ym.fsf@DeuxExMachina.config \
    --to=yggdrasil@gmx.co.uk \
    --cc=ding@gnus.org \
    --cc=nsivaram.net@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).