unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to dynamically select msmtp profile when sending a message?
@ 2024-06-12 21:02 Adham Omran
  2024-06-13 10:18 ` Arash Esbati
  0 siblings, 1 reply; 6+ messages in thread
From: Adham Omran @ 2024-06-12 21:02 UTC (permalink / raw)
  To: help-gnu-emacs

I am trying to set up Emacs to send from multiple accounts, but I am
facing two issues.

In my `/etc/msmtprc` configuration I have two accounts.

1. If one if the accounts is named `default` it always uses and never
automatically picks the correct account to send from based on my FROM
header.

2. If I rename `default` to anything else like `personal` Emacs just
fails to find anything to send from and throws

```
sendmail: account default not found in /etc/msmtprc
```

I want to be able to choose what account to send from, I fear this is
somehow hard coded or not under user choice.

Adham Omran



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to dynamically select msmtp profile when sending a message?
  2024-06-12 21:02 How to dynamically select msmtp profile when sending a message? Adham Omran
@ 2024-06-13 10:18 ` Arash Esbati
  2024-06-13 13:32   ` Adham Omran
  0 siblings, 1 reply; 6+ messages in thread
From: Arash Esbati @ 2024-06-13 10:18 UTC (permalink / raw)
  To: help-gnu-emacs

"Adham Omran" <lists@adham-omran.com> writes:

> I am trying to set up Emacs to send from multiple accounts, but I am
> facing two issues.
>
> In my `/etc/msmtprc` configuration I have two accounts.
>
> 1. If one if the accounts is named `default` it always uses and never
> automatically picks the correct account to send from based on my FROM
> header.
>
> 2. If I rename `default` to anything else like `personal` Emacs just
> fails to find anything to send from and throws
>
> ```
> sendmail: account default not found in /etc/msmtprc
> ```
>
> I want to be able to choose what account to send from, I fear this is
> somehow hard coded or not under user choice.

This is an example configuration from msmtp webpage[1]:

--8<---------------cut here---------------start------------->8---
# Set default values:
defaults
port 587
tls on
tls_starttls on

# Define a mail account at a freemail service
account freemail
host smtp.freemail.example
from joe_smith@freemail.example
auth on
user joe.smith

# Some other mail service
account company
host mail.company.example
from smithjoe@company.example
auth on
user company12345

# Set a default account
account default : freemail
--8<---------------cut here---------------end--------------->8---

So it should work if you're following the above.

Best, Arash

Footnotes:
[1]  https://marlam.de/msmtp/msmtprc.txt




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to dynamically select msmtp profile when sending a message?
  2024-06-13 10:18 ` Arash Esbati
@ 2024-06-13 13:32   ` Adham Omran
  2024-06-13 14:35     ` Arash Esbati
  0 siblings, 1 reply; 6+ messages in thread
From: Adham Omran @ 2024-06-13 13:32 UTC (permalink / raw)
  To: help-gnu-emacs

Arash Esbati <arash@gnu.org> writes:

> "Adham Omran" <lists@adham-omran.com> writes:
>
>> I am trying to set up Emacs to send from multiple accounts, but I am
>> facing two issues.

> This is an example configuration from msmtp webpage[1]:
> ...
> So it should work if you're following the above.

Hey Arash, thank you for your reply, maybe you missed this part in my
initial message:

>> In my `/etc/msmtprc` configuration I have two accounts.

I already have two accounts setup and working with the command line.
Emacs is where I have issues as it does not select the correct account
from my configuration. 

Adham Omran



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to dynamically select msmtp profile when sending a message?
  2024-06-13 13:32   ` Adham Omran
@ 2024-06-13 14:35     ` Arash Esbati
       [not found]       ` <871q506apa.fsf@gilgamesh.mail-host-address-is-not-set>
  0 siblings, 1 reply; 6+ messages in thread
From: Arash Esbati @ 2024-06-13 14:35 UTC (permalink / raw)
  To: help-gnu-emacs

"Adham Omran" <lists@adham-omran.com> writes:

> Hey Arash, thank you for your reply, maybe you missed this part in my
> initial message:
>
>>> In my `/etc/msmtprc` configuration I have two accounts.

Yes, I saw that, but I was just guessing; wrong guess.

> I already have two accounts setup and working with the command line.
> Emacs is where I have issues as it does not select the correct account
> from my configuration. 

I also have a multiple mail-account setup with Emacs/Gnus/msmtp and my
understanding was that msmtp chooses the account based on the
mail-address.  I use message.el for sending messages with:

  (setq message-send-mail-function #'message-send-mail-with-sendmail)
  (setq send-mail-function #'message-send-mail-with-sendmail)
  (setq sendmail-program "/path/to/msmtp")
  (setq message-sendmail-f-is-evil nil)
  (setq message-sendmail-envelope-from 'header)

and have no problems.  For the last 2 forms, you could do:

  (setq message-sendmail-f-is-evil t)
  (setq message-sendmail-extra-arguments '("--read-envelope-from"))

which should give the same result.  Sorry if I'm still missing
something.

Best, Arash




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to dynamically select msmtp profile when sending a message?
       [not found]       ` <871q506apa.fsf@gilgamesh.mail-host-address-is-not-set>
@ 2024-06-13 17:24         ` Arash Esbati
  2024-06-14  5:32           ` Bob Newell
  0 siblings, 1 reply; 6+ messages in thread
From: Arash Esbati @ 2024-06-13 17:24 UTC (permalink / raw)
  To: Adham Omran; +Cc: emacs-help

Adham Omran <lists@adham-omran.com> writes:

> This configuration set made it work for me!
>
> I do not know what the issue was but I suspect it was not reading from
> the headers properly, thank you very much.

You're welcome.  This is from msmtp manual[1]:

  3.3 Choosing an account

  There are three ways to choose the account to use.

  1. --account=account
  Use the given account. Command line settings override configuration
  file settings.
  2. --host=hostname
  Use only the settings from the command line; do not use any
  configuration file data.
  3. --from=address or --read-envelope-from
  Choose the first account from the system or user configuration file
  that has a matching envelope-from address as specified by a from
  command. This works only when neither --account nor --host is used.
  Subadresses are supported. For example, the envelope from address
  user+detail@example.com will match the account for user@example.com.
  Furthermore, the envelope-from address of the account may be a
  wildcard pattern. See from.

  If none of the above options is used (or if no account has a
  matching from command), then the account "default" is used.

The tricky part is to tell msmtp about item 3. which is done by setting
the variables in my message upthread.

Best, Arash

Footnotes:
[1]  https://marlam.de/msmtp/msmtp.html#Choosing-an-account-1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to dynamically select msmtp profile when sending a message?
  2024-06-13 17:24         ` Arash Esbati
@ 2024-06-14  5:32           ` Bob Newell
  0 siblings, 0 replies; 6+ messages in thread
From: Bob Newell @ 2024-06-14  5:32 UTC (permalink / raw)
  To: emacs-help

FWIW, I can confirm that the "secret sauce" is

    (setq message-send-mail-function 'message-send-mail-with-sendmail
       message-sendmail-f-is-evil 't
       sendmail-program "/usr/bin/msmtp"
       message-sendmail-extra-arguments '("--read-envelope-from")
       )

which is similar to that shown above (your msmtp path of course may vary).
I've successfully used msmtp with Emacs/gnus for years with a ridiculous
number of email addresses and accounts.  (It can actually be lots of fun,
especially if used in combination with gnus aliases.)
Bob Newell
Honolulu


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-14  5:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 21:02 How to dynamically select msmtp profile when sending a message? Adham Omran
2024-06-13 10:18 ` Arash Esbati
2024-06-13 13:32   ` Adham Omran
2024-06-13 14:35     ` Arash Esbati
     [not found]       ` <871q506apa.fsf@gilgamesh.mail-host-address-is-not-set>
2024-06-13 17:24         ` Arash Esbati
2024-06-14  5:32           ` Bob Newell

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 read-only IMAP folder(s) and NNTP newsgroup(s).