[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [msmtp-users] Feature request: MX lookups



Hello Mary!

On Sat, 30. Aug 2008, 17:01:13 +1000, Mary Gardiner wrote:
> I am currently using Postfix on my laptop to send out emails, and would
> like to switch to msmtp. There is one feature that's missing that I'd
> like though, and that's supporting MX lookups for the "host" parameter,
> as well as standard A/CNAME lookups.
> 
> Reasons:
>  1. I like to use a couple of different mail relays, and currently
>     support these with MX records, which lets me give them different
>     priorities
> 
>  2. If I have "mail.example.com" having MXs eg "mx1.example.com" and
>     "mx2.example.com" those two hosts do not have to both present a
>     certificate for "mail.example.com" in order to pass certificate
>     sanity checking, they can have different certificates using their
>     individual canonical names

MX lookups, just like queueing or local deliveries, are beyond what
msmtp was originally intended to do. In my opinion, a real MTA should be
used for this. What's wrong with postfix?

That said, there's of course the possibility to enhance msmtp in ways
that were not originally intended ;)  Proper support for MX lookups,
however, is hard to implement in the existing msmtp code base. It would
require some restructuring and redesign. The idea came up before, and I
have gathered some notes about it three of four years ago. Some of the
notes are outdated, but I'll attach the file to this mail; maybe you'll
find it useful.

> I had a look at adding such support myself, but the major stumbling
> block is that I don't have Windows systems to test on. Would a patch be
> useful anyway?

If a feature works and is useful on a POSIX compatible system such as
GNU/Linux, the BSDs, or Mac OS X, then that's fine. A port to Windows
can be done later, if there is interest.

Martin



Notes on MX lookups
===================

Add a special command mx that makes an "account" use the mx domain for
each recipient?
The corresponding option --mx must not be used together with --host.
- Only the following configuration option make sense to be used with mx:
  - domain
  - from
  - keepbcc
  - logfile
  => No authentication! (not a problem)
  => DSN: either forbid it 
          ...or try to use it, but ignore it when it is not supported by
          the remote server???
  => TLS/SSL: either forbid it
          or try to use it, but ignore it when it is not supported by
          the remote server (since MX hosts are not required to support
          TLS/SSL per RFC XXXX). If used, tls-certcheck=off must be
          forced???
When the mx command or --mx option is active, the following steps are
necessary to send the mail:
- Get the list of recipient domains (examine all recipients).
  Recipients without a domain part must be rejected.
- Sort this list. Normalize it (upper/lower case, different methods of
  internationalized domains, ... I don't know if this step is necessary or
  taken care of by the resolver lib). Delete dups.
  Recipients: joe@...162... john@...163... test1@...20... test2@...164... ... 
  Recipient domains: smith.com gmail.com  
- Sort the recipients by the recipient domains
  smith.com -> gmail.com -> ...
      |            |
      V            V
  joe@           test1@
  john@          test2@
- Find a list of MX hosts (sorted by preference) for each recipient
  domain. Use mxget.* from fetchmail?
  smith.com       ->    gmail.com            -> ...
  (mx1.smith.com)       (gsmtp1.google.com)
  (mx2.smith.com)       (gsmtp2.google.com)
      |                      |
      V                      V
  joe@                    test1@
  john@                   test2@
- For each recipient domain:
  - Connect to the first SMTP server in the MX list
  - Send the mail to each recipient in the corresponding recipient list
    (if we're currently connected with mx1.smith.com, send the mail to
    joe@...162... and john@...162...).
  - If this fails, try the next SMTP server in the MX list
  - ABORT when all MX servers failed, even if they report temporary
    errors, since msmtp has no queueing support
To be able to send the mail multiple times (this is necessary only if we
have more than one recipient domain), it must be stored in a
temporary file (which can be rewinded; stdin cannot be rewinded).
This interferes with temp file usage of -t as it is implemented now.
The usage of msmtp_read_recipients() needs to be changed, we only want
to run it once.
Some fundamental changes have to be done in msmtp_sendmail(), because
msmtp was written to send the mail to exactly one SMTP server.