Re: Using several SMTP servers

2022-08-12 Thread Sam Kuper
On Fri, Aug 12, 2022 at 10:57:41PM +0200, Sébastien Hinderer wrote:
> As I see it, the SMTP configuration to use is fully determined by the
> from address of the mail to be sent.
> 
> [...] there shouldn't be any need for interactivity. For each outoging
> mail, pick up the right SMTP config based on who (which address) is
> sending (From header). As simple as that, I think.

Great!  In that case, msmtp and msmtp-queue can handle your requirements
without modification.  Just populate the config files per your needs,
set up a cron job if you want it, and hopefully your SMTP woes are over!

Sam


Re: Using several SMTP servers

2022-08-12 Thread Sébastien Hinderer
Hey Sam, many thanks, again, for your response,

Sam Kuper (2022/08/12 19:56 +):
> CASE 1
> 
> IIRC, msmtp can be configured to use a different smarthost per *email
> address*.  (To emphasise: you would set that up in msmtp's config, not
> in msmtp-queue's config.  msmtp-queue doesn't really have or need much
> configuration.)  So, if that's what you meant, then yes, it's possible.
> 
> 
> CASE 2

I am definitely in that case. Thanks for having raised the point,
because it was obvious to me but, fortunately for everybody, not
everybody is living in my head.

As I see it, the SMTP configuration to use is fully determined by the
from address of the mail to be sent.

> If, instead, you want to be able to choose, per outgoing *email* (rather
> than per *email address* of yours), which smarthost to use, then I think
> you would have to either:
> 
> -   write a wrapper for msmtp-queue to give you an interactive menu for
> choosing which smarthost to use for each outgoing email you send, or
> 
> -   rewrite your installed msmtp-queue script to give you such a menu.

Again, as I see it, there shouldn't be any need for interactivity. For
each outoging mail, pick up the right SMTP config based on who (which
address) is sending (From header). As simple as that, I think.

And, thanks a lot for the idea of installing msmtp manally rather than
through the package manager. It should be possible, I think, to handle
it with the package manager, because manually installing is a pain, but
as long as it's not, that sounds like a good idea.

Once I'll have everything set-up, if I manage to, I'll report here,
either in this thread, or in a dedicated one.

Cheers,

Sébastien.


Re: Using several SMTP servers

2022-08-12 Thread Sam Kuper
On Fri, Aug 12, 2022 at 08:53:23PM +0200, Daniel Tameling wrote:
> On Fri, Aug 12, 2022 at 03:58:02PM +, Sam Kuper wrote:
>> -   Test/tweak/re-test msmtp until working.  (E.g. using Mutt or GNU
>> Mailutils's `mail` command to send emails from the command-line,
>> with relevant command-line options set so as to ensure that msmtp
>> is used as the MTA).  Hopefully it would work first time, if
>> configured correctly and if your computer has a suitable internet
>> connection.
> 
> You can check whether msmtp is working with just the echo command.

Good point - I had forgotten that.  Thanks!

Sam


Re: Using several SMTP servers

2022-08-12 Thread Sam Kuper
On Fri, Aug 12, 2022 at 07:01:52PM +0200, Sébastien Hinderer wrote:
> 1. Am I correct that it will be possible, when calling smstp-queue, to
> specify which smarthost to use?
> 
> In other words, am I correct that this will let me associate one smart
> host (SMTP configuration) to each mail in the queue, rather than using
> the smae smarthost for allthe mails in the queue?

CASE 1

IIRC, msmtp can be configured to use a different smarthost per *email
address*.  (To emphasise: you would set that up in msmtp's config, not
in msmtp-queue's config.  msmtp-queue doesn't really have or need much
configuration.)  So, if that's what you meant, then yes, it's possible.


CASE 2

If, instead, you want to be able to choose, per outgoing *email* (rather
than per *email address* of yours), which smarthost to use, then I think
you would have to either:

-   write a wrapper for msmtp-queue to give you an interactive menu for
choosing which smarthost to use for each outgoing email you send, or

-   rewrite your installed msmtp-queue script to give you such a menu.

The menu part (UI) isn't so hard, but implementing the underlying
functionality would be a bit more work.



> 2. I think one of the things for which exim is used is the local
> delivery of e-mails. So for instance thee-mails from the cron user are
> delivered to root, but then the e-mails from root are delivered to my
> main local user account and I think it's exim which deals with this
> bit

Yes, lots of GNU/Linux boxes are set up like that by default.


> and I probably won't touch that, unless I have to.

Quite right.


> Also, there is a subtlety that I'll need to figure out, on Debian.
> there are two packages: msmtp and msmtp-mta. the second one conflicts
> with exim son both can not coexist on the same system (they both
> provide the mail-transpor-agent package). At least that's my
> understanding.
> 
> Indeed if I try to install msmtp-mta it wants to remove 7 packages:
> exim4 exim4-base exim4-config exim4-daemon-light libgsasl7
> libmailutils6 libmu-dbm6. So I'll start with msmtp alone and see what
> happens, perhaps.

Alternatively, just install msmtp outside of Debian's package management
system?  msmtp is (by design, I believe) quite lightweight/standalone,
so it's a good candidate for that approach.

Good luck, either way!

Sam


Re: Using several SMTP servers

2022-08-12 Thread Sébastien Hinderer
Daniel Tameling (2022/08/12 20:53 +0200):
> On Fri, Aug 12, 2022 at 03:58:02PM +, Sam Kuper wrote:
> > -   Test/tweak/re-test msmtp until working.  (E.g. using Mutt or GNU
> > Mailutils's `mail` command to send emails from the command-line,
> > with relevant command-line options set so as to ensure that msmtp is
> > used as the MTA).  Hopefully it would work first time, if configured
> > correctly and if your computer has a suitable internet connection.
> 
> You can check whether msmtp is working with just the echo command. See the
> "Test functionality" section at https://wiki.archlinux.org/title/msmtp
> 
> The whole page is valuable if your starting with msmtp.

Many thanks for the link!

Sébastien.


Re: Using several SMTP servers

2022-08-12 Thread Daniel Tameling
On Fri, Aug 12, 2022 at 03:58:02PM +, Sam Kuper wrote:
> -   Test/tweak/re-test msmtp until working.  (E.g. using Mutt or GNU
> Mailutils's `mail` command to send emails from the command-line,
> with relevant command-line options set so as to ensure that msmtp is
> used as the MTA).  Hopefully it would work first time, if configured
> correctly and if your computer has a suitable internet connection.

You can check whether msmtp is working with just the echo command. See the
"Test functionality" section at https://wiki.archlinux.org/title/msmtp

The whole page is valuable if your starting with msmtp.

--
Best regards,
Daniel


Re: Using several SMTP servers

2022-08-12 Thread Sébastien Hinderer
Thanks a lot, Sam!

Everything you write makes sense.

Just one question and one remark, if you don't mind.

1. Am I correct that it will be possible, when calling smstp-queue, to
specify which smarthost to use?

In other words, am I correct that this will let me associate one smart
host (SMTP configuration) to each mail in the queue, rather than using
the smae smarthost for allthe mails in the queue?

2. I think one of the things for which exim is used is the local
delivery of e-mails. So for instance thee-mails from the cron user are
delivered to root, but then the e-mails from root are delivered to my
main local user account and I think it's exim which deals with this bit
and I probably won't touch that, unless I have to.

Also, there is a subtlety that I'll need to figure out, on Debian. there
are two packages: msmtp and msmtp-mta. the second one conflicts with
exim son both can not coexist on the same system (they both provide the
mail-transpor-agent package). At least that's my understanding.

Indeed if I try to install msmtp-mta it wants to remove 7 packages:
exim4 exim4-base exim4-config exim4-daemon-light libgsasl7 libmailutils6
libmu-dbm6. So I'll start with msmtp alone and see what happens,
perhaps.

Cheers,

Sébastien.


Re: Using several SMTP servers

2022-08-12 Thread Sam Kuper
On Fri, Aug 12, 2022 at 04:05:55PM +0200, Sébastien Hinderer wrote:
> Hello Sam, many thanks for your interesting response!

:)

> Sam Kuper (2022/08/11 17:43 +):
>> Consider using msmtp for sending, and msmtp-queue for queueing:
>>
>> https://lists.mutt.org/pipermail/mutt-users/Week-of-Mon-20210208/002485.html
> 
> My understanding is that, on one side, mutt would call msmtp-queue as
> a replacement for sendmail

Yes

> and that, on the other side, msmtp needs to somehow be called on a
> regular basis to try to send the messages that are in the queue, if
> network is available. Is this understanding correct?

`msmtp-queue -r` tells msmtp to try to send the emails from
msmtp-queue's queue to your mail provider's SMTP server.  In order for
that to succeed, you need to have a network connection - otherwise the
attempt will time-out and the queued mails will stay in msmtp-queue's
queue so that you can try again later.

So, you can:

-   Manually run `msmtp-queue -r` when you know you have an internet
connection, or

-   Set up a cron-job to run `msmtp-queue -r` according to your
preferred schedule (e.g. every 2 minutes), or

-   Some combination of the two (i.e. have a cron-job set up, but
manually invoke `msmtp-queue -r` on occasions when you don't want to
wait for the next cron time-point).

It's your choice.



> Also, given how important e-mail is, I am a bit worried about the
> transition: any advice on how to switch from exim4 to this new set-up
> as smoothly as possible and without risking to be unable to send
> e-mail for some time?

Here is what I would do in that situation:

-   Read msmtp and msmtp-queue's documentation.

-   Install and configure msmtp.

-   Test/tweak/re-test msmtp until working.  (E.g. using Mutt or GNU
Mailutils's `mail` command to send emails from the command-line,
with relevant command-line options set so as to ensure that msmtp is
used as the MTA).  Hopefully it would work first time, if configured
correctly and if your computer has a suitable internet connection.

-   Install msmtp-queue (it comes bundled with msmtp IIRC) and configure
it, including setting up a cron-job if you want one.

-   Test/tweak/re-test msmtp-queue (similarly to testing msmtp).

-   Edit your muttrc to tell Mutt to use msmtp-queue instead of Exim.

-   Check to see if you have anything else installed that depends on
Exim.

-   If so, either leave it as is (probably) or find another solution
for those things (if you really want to - but Exim is good for
its intended use case).

-   If not, then uninstall Exim.

Good luck!

Sam


Re: Using several SMTP servers

2022-08-12 Thread Derek Martin
On Thu, Aug 11, 2022 at 06:23:56PM +0200, Sébastien Hinderer wrote:
> Dear all,
> 
> Sorry if the question is off-topic, hopefully not completely though.
> 
> I am wondering what's the best way to use different SMTP servers to send
> mails, depending on which e-mail account I am currently using (the From 
> address).

There is arguably no best way; the best way *for you* will be specific
to how you use mail.  There are a number of ways to do this, but I
think the two most workable ones are:

1. Use hooks (e.g. folder-hook, send-hook, etc.) to set the variables
   for your smtp configuration, based on the folder you're in, the
   recipient you're sending to, etc..  See the mutt manual for more
   details on how to use hooks.

2. Use a macro, bound to some key, that changes the variables when you
   press it.  Again, the manual will have the details, but you might
   want to have a look at this:

 https://gitlab.com/muttmua/mutt/-/wikis/MuttGuide/Macros

There are other ways, like starting mutt with a different config file,
etc., and probably more that I haven't thought of, but I think one of
the two above will be easiest to manage.

-- 
Derek D. Martinhttp://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.



signature.asc
Description: PGP signature


Re: Using several SMTP servers

2022-08-12 Thread Sébastien Hinderer
Hello Sam, many thanks for your interesting response!

Sam Kuper (2022/08/11 17:43 +):
> Consider using msmtp for sending, and msmtp-queue for queueing:
> 
>
>https://lists.mutt.org/pipermail/mutt-users/Week-of-Mon-20210208/002485.html

My understanding is that, on one side, mutt would call msmtp-queue as a
replacement for sendmail and that, on the other side, msmtp needs to
somehow be called on a regular basis to try to send the messages that
are in the queue, if network is available. Is this understanding
correct?

Also, given how important e-mail is, I am a bit worried about the
transition: any advice on how to switch from exim4 to this new set-up as
smoothly as possible and without risking to be unable to send e-mail for
some time?

I am considering trying on a different machine, or perhaps in a chroot
or docker container, although even with these two last options I am
scared because once in the past I deleted my whole home directory by
removing a chroot in which that home directory was bind-mounted. Since
then I have backups, but still...

Best wishes,

Sébastien.


Re: Using several SMTP servers

2022-08-11 Thread Sam Kuper
On Thu, Aug 11, 2022 at 06:23:56PM +0200, Sébastien Hinderer wrote:
> So far I use exim4 to send e-mails but I didn't see a way to specify
> which "smarthost" to use to send e-mails e.g. on the sendmail command
> line. So, even if I could use mutt send hooks to choose which SMTP
> configuration to use based on my From address, I don't know how to
> pass this information to the MTA and I am assuming this should not
> even happen.
> 
> One other alternative may be to let mutt send e-mails to SMTP servers
> itself, directly, without going through sendmail/exim4, but then I am
> wondering what is going to happen if I try to send an e-mail while my
> computer is off-line. Am I correct that mutt has no queue or
> whatsoever that would allow it to defer sending e-mails until the
> computer is back online, which is exactly what the MTA does?
> 
> I can't come up with a satisfactory solution and would really
> appreciate feedback on this topic.

Consider using msmtp for sending, and msmtp-queue for queueing:

https://lists.mutt.org/pipermail/mutt-users/Week-of-Mon-20210208/002485.html

Sam


Using several SMTP servers

2022-08-11 Thread Sébastien Hinderer
Dear all,

Sorry if the question is off-topic, hopefully not completely though.

I am wondering what's the best way to use different SMTP servers to send
mails, depending on which e-mail account I am currently using (the From 
address).

I do realise that the two things (the SMTP server used to send an e-mail
on the one hand, and the e-mail address in the From header of that mail
on the other hand) are not necessarily related and that's actually
my current setting: I use the same SMTP server, with authentication,
no matter where I am and no matter which e-mail address there is
in the From header of the e-ml am sending.

My question is: can that be changed and, if yes, how.

So far I use exim4 to send e-mails but I didn't see a way to specify
which "smarthost" to use to send e-mails e.g. on the sendmail command
line. So, even if I could use mutt send hooks to choose which SMTP
configuration to use based on my From address, I don't know how to pass
this information to the MTA and I am assuming this should not even happen.

One other alternative may be to let mutt send e-mails to SMTP servers
itself, directly, without going through sendmail/exim4, but then I
am wondering what is going to happen if I try to send an e-mail while
my computer is off-line. Am I correct that mutt has no queue or
whatsoever that would allow it to defer sending e-mails until the
computer is back online, which is exactly what the MTA does?

I can't come up with a satisfactory solution and would really appreciate
feedback on this topic.

Many thanks in advance,

Sébastien.