Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Volkan YAZICI <volkan.yazici@gmail.com>
To: info-gnus-english@gnu.org
Subject: Re: Multiple smtpmail Accounts
Date: 8 Nov 2007 11:25:56 -0800	[thread overview]
Message-ID: <1194525584.114989.13840@e9g2000prf.googlegroups.com> (raw)
In-Reply-To: <87ir4evx0t.fsf@gnu.org>

On Nov 7, 6:30 pm, Exal de Jesus Garcia Carrillo <no-s...@gnu.org>
wrote:
> Volkan YAZICI em gnu.emacs.gnus escreveu :
> > How can I make smtpmail to select between different servers defined in
> > smtpmail-starttls-credentials and smtpmail-auth-credentials by looking
> > at "From:" header of the about to be sent post?
>
> IIRC, many times was posted something similar

Sorry, I searched the archives but couldn't find anything related. I
should have missed something.

> I use a function (take it from some place, IIRC from Tassilo)
> for this, these is in some place in my .emacs file
>
> http://exal.nipl.net/.emacs

Thanks for the pointer. I have modified the code a little bit, and
here is the solution I use:

(setq
 send-mail-function 'smtpmail-send-it
 message-send-mail-function 'smtpmail-send-it
 mail-from-style nil
 user-full-name "Johnny B. Good"
 smtpmail-debug-info t
 smtpmail-debug-verb t)

(defun set-smtp (server port user password)
  "Set related SMTP variables for supplied parameters."
  (setq smtpmail-smtp-server server
        smtpmail-smtp-service port
        smtpmail-auth-crendentials `((,server ,port ,user ,password)))
  (message "Setting SMTP server to `%s:%s' for user `%s'."
           server port user))

(defun set-smtp-with-ssl (server port user password 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-auth-credentials `((,server ,port ,user ,password))
        smtpmail-starttls-credentials `((,server ,port ,key ,cert)))
  (message
   "Setting SMTP server to `%s:%s' for user `%s'. (SSL enabled.)"
   server port user))

(defun change-smtp ()
  "Change the SMTP server according to the current from line."
  (save-excursion
    (let ((from
           (save-restriction
             (message-narrow-to-headers)
             (message-fetch-field "from"))))
      (cond
       ((string-match "me@foo.com" from)
        (set-smtp "smtp.foo.com" 25 "me" nil))
       ((string-match "me@bar.com" from)
        (set-smtp-with-ssl
         "smtp.bar.com" 587 "me@bar.com" nil nil nil))
       (t (error "Cannot interfere SMTP information."))))))

Implementing change-smtp in a more user-friendly fashion is left as an
exercise for the reader. And some more configuration for Gnus:

(setq gnus-posting-styles
      '((".*" (address "me@foo.com"))
        ("bar" (address "me@bar.com")))


Regards.

  reply	other threads:[~2007-11-08 19:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-07 14:32 Volkan YAZICI
2007-11-07 16:30 ` Exal de Jesus Garcia Carrillo
2007-11-08 19:25   ` Volkan YAZICI [this message]
2007-11-07 17:05 ` CHENG Gao

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=1194525584.114989.13840@e9g2000prf.googlegroups.com \
    --to=volkan.yazici@gmail.com \
    --cc=info-gnus-english@gnu.org \
    /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).