Discussion:
separate smtps for my accounts
Sharon Kimble
2014-09-12 00:58:20 UTC
Permalink
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?

Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.93.1
Eric Abrahamsen
2014-09-12 02:08:29 UTC
Permalink
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?
Thanks
Sharon.
The details depend a little bit on the exact program you're using for
sending mail, but generally the rigmarole looks like this (I use msmtp):

(defun cg-feed-msmtp ()
(if (message-mail-p)
(save-excursion
(let* ((from
(save-restriction
(message-narrow-to-headers)
(message-fetch-field "from")))
(account
(cond
;; I use email address as account label in ~/.msmtprc
((string-match "***@ericabrahamsen.net" from) "ea")
((string-match "***@gmail.com" from) "acc2")
((string-match "***@domain.org" from) "more"))))
(setq message-sendmail-extra-arguments (list '"-a" account))))))

(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'cg-feed-msmtp)
Jorge A. Alfaro-Murillo
2014-09-12 15:05:56 UTC
Permalink
Post by Eric Abrahamsen
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts,
but only one smtp address. How can I have a separate smtp
settings so that I am able to reply via the address of the
email that I've just received?
Thanks Sharon.
The details depend a little bit on the exact program you're
using for sending mail, but generally the rigmarole looks like
(defun cg-feed-msmtp ()
(if (message-mail-p)
(save-excursion
(let* ((from (save-restriction (message-narrow-to-headers)
(message-fetch-field "from"))) (account (cond ;; I use email
address as account label in ~/.msmtprc ((string-match
message-sendmail-extra-arguments (list '"-a" account))))))
(setq message-sendmail-envelope-from 'header) (add-hook
'message-send-mail-hook 'cg-feed-msmtp)
I have two smtp addresses, one for work and a personal one at
Gmail, and I used to have a similar setup. But I discovered
recently that you can configure Gmail to send mail from another
address (In Gmail: Settings, Accounts and Import, Send mail as),
so I just left my smtpmail with gmail, and now Gmail decides from
where to send the email according to the "From" field in the
message.

I set up my user-mail-address as my work email, since that is the
one I generally use, and then use gnus-posting-styles, so that if
someone sends me a personal email, I reply using the personal
email:

#+BEGIN_SRC emacs-lisp
(setq gnus-posting-styles
`(
...
((header "To" ,(regexp-quote "***@gmail.com"))
(address "***@gmail.com"))
((header "CC" ,(regexp-quote "***@gmail.com"))
(address "***@gmail.com"))
((header "BCC" ,(regexp-quote "***@gmail.com"))
(address "***@gmail.com"))
...

#+END_SRC

This method has the advantage of keeping a copy of the sent mail
from the work address in the Sent Mail folder of Gmail, so all
sent mail is in one place.


Best,
--
Jorge.
Sharon Kimble
2014-09-13 22:03:03 UTC
Permalink
Post by Eric Abrahamsen
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?
Thanks
Sharon.
The details depend a little bit on the exact program you're using for
I'm using whatever the default is with Debian testing, sorry! Exim4? I
don't know what it is, but reportbug is able to send through it.

Sharon.
Post by Eric Abrahamsen
(defun cg-feed-msmtp ()
(if (message-mail-p)
(save-excursion
(let* ((from
(save-restriction
(message-narrow-to-headers)
(message-fetch-field "from")))
(account
(cond
;; I use email address as account label in ~/.msmtprc
(setq message-sendmail-extra-arguments (list '"-a" account))))))
(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'cg-feed-msmtp)
--
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.93.1
Eric Abrahamsen
2014-09-14 02:01:49 UTC
Permalink
Post by Sharon Kimble
Post by Eric Abrahamsen
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?
Thanks
Sharon.
The details depend a little bit on the exact program you're using for
I'm using whatever the default is with Debian testing, sorry! Exim4? I
don't know what it is, but reportbug is able to send through it.
Sharon.
Here's what I've got for mail sending setup, what is your value of
message-send-mail-function?

(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq sendmail-program "msmtp")
Sharon Kimble
2014-09-16 18:57:59 UTC
Permalink
Post by Eric Abrahamsen
Post by Sharon Kimble
Post by Eric Abrahamsen
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?
Thanks
Sharon.
The details depend a little bit on the exact program you're using for
I'm using whatever the default is with Debian testing, sorry! Exim4? I
don't know what it is, but reportbug is able to send through it.
Sharon.
Here's what I've got for mail sending setup, what is your value of
message-send-mail-function?
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq sendmail-program "msmtp")
Thanks Eric, here’s what I have -

--8<---------------cut here---------------start------------->8---
(setq smtpmail-smtp-server "relay.plus.net")
(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
(require 'smtpmail)

(setq smtpmail-auth-credentials "~/.authinfo")
--8<---------------cut here---------------end--------------->8---

Sharon.
--
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.93.1
Eric Abrahamsen
2014-09-17 02:17:06 UTC
Permalink
Post by Eric Abrahamsen
Post by Sharon Kimble
Post by Eric Abrahamsen
Post by Sharon Kimble
In my gnus setup I have 1 pop3 account, and 3 imap accounts, but only
one smtp address. How can I have a separate smtp settings so that I am
able to reply via the address of the email that I've just received?
Thanks
Sharon.
The details depend a little bit on the exact program you're using for
I'm using whatever the default is with Debian testing, sorry! Exim4? I
don't know what it is, but reportbug is able to send through it.
Sharon.
Here's what I've got for mail sending setup, what is your value of
message-send-mail-function?
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq sendmail-program "msmtp")
Thanks Eric, here’s what I have -
(setq smtpmail-smtp-server "relay.plus.net")
(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
(require 'smtpmail)
(setq smtpmail-auth-credentials "~/.authinfo")
I'm not doing what you're doing, so I won't be able to help you
directly, but I'll bet you can find a good solution on this page:

http://www.emacswiki.org/emacs/MultipleSMTPAccounts

Check the section starting "In the recently released Emacs 24.1, one
could utilitize the fact..."

A unified or built-in solution for this would be pretty nice...

E
Ted Zlatanov
2014-09-24 15:24:56 UTC
Permalink
On Wed, 17 Sep 2014 10:17:06 +0800 Eric Abrahamsen <***@ericabrahamsen.net> wrote:

EA> A unified or built-in solution for this would be pretty nice...

1) in my ~/.authinfo.gpg

#+begin_src text
machine smtp.gmail.com login ***@px.com port 587 password "pass1"
machine smtp.gmail.com login ***@lifelogs.com password "pass2"
#+end_src

2) I use this function, original author unknown:

#+begin_src lisp
(defun tzz-change-smtp ()
"Change the SMTP server according to the current from line."
(save-excursion
(save-restriction
(message-narrow-to-headers)
(let* ((from (message-fetch-field "from"))
(from-px (string-match "px" from))
)
(cond
(from-px
(setq smtpmail-smtp-service 587
smtpmail-smtp-user "***@px.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-default-smtp-server smtpmail-smtp-server))
(t
(setq smtpmail-smtp-service 587
smtpmail-smtp-user "***@lifelogs.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-default-smtp-server smtpmail-smtp-server)))))))

(add-hook 'message-send-hook 'tzz-change-smtp)
#+end_src

So basically the `smtpmail-smtp-user' and `smtpmail-smtp-server' are
matched against ~/.authinfo.gpg.

This is essentially what posting-styles is designed for. Does it look
robust enough to add support for it to the posting styles? Or is it
already supported? Sorry, I'm a bit out of date on this stuff :)

If we find a solution that works out of the box, we can add it to the
auth-source manual and tell people about it: (info "(auth) Help for users")

Ted

Rasmus
2014-09-17 12:32:13 UTC
Permalink
Hi Sharon,
Post by Eric Abrahamsen
Here's what I've got for mail sending setup, what is your value of
message-send-mail-function?
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq sendmail-program "msmtp")
Thanks Eric, here’s what I have -
(setq smtpmail-smtp-server "relay.plus.net")
(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
(require 'smtpmail)
You may be making your life more complicated than necessary.

Must you use a separate program? Gnus communicates via smtp out of
the box. I suggest you look into X-Message-SMTP-Method and posting
styles.

Here's my posting style for inspiration. I have no other mention of
smtp in my init.el.

(setq gnus-posting-styles
'(((lambda ()
(rasmus/gnus-posting-style-identify ".*" `("To". ,(regexp-quote "mydom.com")) nil))
(GCC "nnimap+mail:mydomain/sent")
(X-Message-SMTP-Method "smtp ssl.mydomain.com 465 rasmus")
(signature (cookie
(expand-file-name "signatures" user-emacs-directory) "" ""))
(Face (gnus-random-face))
(eval (setq smtpmail-stream-type 'ssl)))
((lambda ()
(rasmus/gnus-posting-style-identify
"school" `("To" . ,(regexp-quote "***@school.com"))
(lambda () (rasmus/message-mailto-test (regexp-quote "school.com")))))
(address "***@school.com")
(Face (gnus-convert-png-to-face
(expand-file-name "school.png" gnus-face-directory)))
(Organization "school")
(GCC "nnimap+mail:school/sent")
(X-Message-SMTP-Method "smtp outlook.com 587 ***@school.com")
(signature "school")
(eval (setq smtpmail-stream-type nil)))
((lambda ()
(rasmus/gnus-posting-style-identify
(regexp-opt '("gmx" "gmane" "sunsite" "emacs"))
`("To" . ,(regexp-quote "***@gmx.us")) 'message-news-p))
(name "Rasmus")
(address "***@gmx.us")
(Organization nil)
(GCC "nnimap+mail:gmx/sent")
(X-Message-SMTP-Method "smtp mail.gmx.com 587 ***@gmx.us")
(eval (setq smtpmail-stream-type nil)))))
(setq smtpmail-auth-credentials "~/.authinfo")
BTW: Emacs can handle .authinfo.gpg out of the box.

Hope it helps,
Rasmus
Eric S Fraga
2014-09-17 08:37:38 UTC
Permalink
On Saturday, 13 Sep 2014 at 23:03, Sharon Kimble wrote:

[...]
Post by Sharon Kimble
I'm using whatever the default is with Debian testing, sorry! Exim4? I
don't know what it is, but reportbug is able to send through it.
With exim4 (which I find overly complicated), I have no idea how to do
what you want.

With msmtp, it is easy however. You define specific gnus-posting-styles
based on groups and define the address for each case, including the
default catch-all case. In the msmtp configuration, i.e. the .msmtprc
file, you then have an entry for the various servers which matches the
"from" specification with the address specified in gnus.

I can give more specific examples if you end up switching to msmtp but
this has been discussed previously on this list so you may be able to
find examples yourself.

HTH,
eric
--
: Eric S Fraga, GnuPG: 0xFFFCF67D
: in Emacs 24.4.50.1 + Ma Gnus v0.12 + evil-git-0469bee
: BBDB version 3.1.2 (2014-05-06 11:45:08 -0500)
Loading...