Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my first try on implementing direct send #386

Closed
wants to merge 1 commit into from

Conversation

cbergmann
Copy link

As you pointed out in Your issue 119 it would be usefull to be able to send mails directly to the recipients mail Server. This allows more direct responses about wrong mail Adresses etc.

This is my first try on this topic.

What Do you think about this?

best regards
Clemens

@Synchro
Copy link
Member

Synchro commented Mar 25, 2015

Thanks for having a go! I don't think you should implement this as another sending mechanism, because it's just going to be using SMTP anyway. All it needs is auto-setting of the SMTP host from the recipient address. I think your getMXforAddress function should limit itself to DNS lookups - making SMTP connections in here is a bit pointless because it will be doing that when it tries to send anyway, and will make it much slower and complicate error reporting.

Rather than the separate send mechansim I think it would be better to set some kind of 'autohost' flag so that the SMTP send does a lookup for the Host value, ignoring the manually provided one. That should make things quite a bit simpler. As far as TLS goes, nearly all servers will accept incoming mail without encryption, but it would be useful to have a kind of 'autotls', which could be done by making use of the server capabilities array that was added recently.

Alternatively, it could be simplified quite a bit by only providing the getmxforaddress function - that would only work for sending to one domain at a time, but that's all that usually done.

@cbergmann
Copy link
Author

Hi,

There are three parts in your answer:

First about splitting the smtp connections:
My first implementation was by modifying the smtpSend function. The problem is that the recipients are likely from different domains and therefore we need different SMTP connections for each recipient (or at least for each domain). We could group the recipients by domain to reduce the connections.

Second about how to find the MX Server for each domain:
An interesting part about how to prevent Spam with specially crafted MX entrys can be found in the SpamAssassin Wiki. This (and the TLS autodetection) is the reason why I did the connections in descending preference order and returned the first matched smtp server. On second thought it would be possible to merge these two steps.
We could just get MX "candidates" in the getMXforAddress function and then loop over them trying to connect. When we successfully connect to one we could reuse this connection to send the mail. (possibly including TLS autodetection). This (in combination with the recipient-grouping from above) could reduce the SMTP connections to the minimum of one connection per domain.

Last about TLS autodetection:
I agree that it is a better way to do it like you did. Especially because that would also effect "smtpSend" connections and would therefore increase the overall security.

@Synchro
Copy link
Member

Synchro commented Mar 25, 2015

Grouping multiple addresses in the same domain would be a sensible idea, and caching the successful host value to use for all of them would be good too.

Yes, I think that getmxforaddress should just return a list of candidates - the Host property already has support for trying to deliver to a list of hosts, so you would just stick the results into that for each message.

One limitation is that while it can use keepalive and send to multiple recipients, it's only expecting to use one Host value and one connection for each message sent (i.e. for all recipients), so you could not use it to send this way for multiple domains - you would have to break your to/cc/bcc lists up by domain ahead of time, and keepalive ceases to be of any value as different domains will have different Host values, and thus can't use the same connection.

The problem I see with the direction this is all going is that we're starting to turn into an MTA - all this handling of multiple MXs is ok, but we need to remember that probably the vast majority of the millions of PHPMailer users are sending to one recipient during a page load. Thus it's not tolerable to have long delays that the fake MXs would no doubt incur. Most users are using a local mail server or nearby smarthost (like gmail), and anyone sending seriously will be using a proper MTA anyway, at which point we have no need for direct sending anyway. I think this is why there has not been much demand for this feature to date.

@Synchro Synchro closed this Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants