Not a bug Bugs in automatic bounce email handler

pmoi

New member
Affected version
XF 2.2
Last week I asked if anybody has an working example of an bounce email that the automatic bounce handler recognizes.
i got no answers as I was afraid since almost all discussion about this handler show almost nobody has it working and many people giving up on it.
I don't know if even xenforo has it working on their own boards that they operate.

My system is different from most others of you since I do not get an email but rather an webhook from email provider if email bounces and therefore I have the freedom to craft any kind of email I want based on the webhook I get then to be sent to the xenforo automatic email bounce handler.

The example bounce emails I get from sptm.gmail.com and smtp.zoho.com neither works to get recognized in the automatic bounce handler so something is wrong.

Well, I had some spare time and after sending about 100 different test bounce emails I finally got a working system for me where I can send an email and it gets recognized. During this process I encountered some bugs that I needed to work around to get the emails recognized.

The good news is that both of these problems sound like very easy to fix and there seems to be a bunch of working code in the backend of the system if just emails would get past the recognizing phase of the automatic email handler.

The main problem seems to be related to line breaks of the email.

How the email system works is that while sending emails there are extra line breaks added to the email content body which the receiving end is supposed to strip out before handing the email contents to the recipient. Xenforo has forgot to put this stripping of extra line breaks part of the process of receiving emails into their system and so these extra line breaks are left into the content body and they work as corruption preventing the automatic handler to correctly read the interesting parts of the email. You can see these extra line breaks if you go look at the raw contents of received emails.

The extra line breaks are added to about every 70th character in the email body and since there seems to be 3 important sections that the automatic handler looks for and each of these important sections are about 20-40 characters long the probability that none of the important sections are corrupted is about 10%. 90% of the bounce emails fail at this first step.

Except if one ticks the box in option "Enable variable email address values for automated email handling" which makes the email address that the automatic handler is supposed to read from the content much longer meaning that the probability that this longer email address survives the corruption from extra line breaks is almost zero.

The process of adding line breaks is deterministic so some email service provider could send bounce emails that happen to have all important sections of the bounce email uncorrupted and this might be the reason this feature was working when somebody wrote the code to xenforo without noticing that it is missing important part of the system which makes so that almost none of other email service provider bounce emails are similarly lucky. Some of them could be lucky though so somebody could have this feature working right now. However that percentage is likely to be too small to have anybody of those lucky individuals to show up on this xenforo support forum.

There is still another additional problem though. It seems like the automatic bounce handler is looking for some english language abracadabra that triggers the whole detection process. This seems also very fragile system as every email service provider can send their bounce emails with completely different sections of english language explanations. The bounce emails from gmail and zoho look completely different and one from gmail does not seem to contain the right abracadabra and so the automatic handler seems to discard all bounces from smtp.gmail.com right away.

I think the abracadabra check needs to be made more universal so that many different kinds of bounce emails from multiple email service providers have a hope of getting recognized. One way to do this is to make the abracadabra to be user configurable by instructing the forum administrator to take look what kind of bounce emails his email service provider sends and forum administrator picks some abracadabra section that he then configures into xenforo to look for.

Another possible approach is for xenforo to choose some number of biggest email service providers and add support for each of their abracadabra to maintain support for these X number of supported email service providers which xenforo then makes public to recommend those providers.

Without doing something to this abracadabra problem I don't think the probability of getting bounce emails recognized can get over 50%.

There could be a problem also in the handling of the error code to detect either hard or soft bounce. I just got the feeling that it might be fragile during testing but since I got the system working for me I did not prod this issue further.

These are my observations. There seems to be a lot of good code in the backend if only this bounce email recognization problems are fixed and both of these problems sound very easy to fix.

If some xenforo developer wants to get my email format that I achieved to get working past the automatic detection you can email me and I will send it. It is unlikely to help anybody else right now since most of you are at the mercy of whatever your email service provider happens to send to you and there is nothing you can do to help this.
 
I do use this feature on one of my forums, and it works fine. A "hard bounce" is the most serious, and it will automatically set their user record to BOUNCED - and will ask them to pick a new email on their next visit. "Soft Bounce" is more of a warning in the log, for minor issues. (mailbox full, re try, etc) Vacation replies also come back and go to the logs, for review.

It was a bit of trial and error to figure out how to get it working initially, but that was over a year ago.
 
Thank you for the extensive explanation.

To answer the question about whether the feature works, including on our own forums, absolutely it does. I'm not sure what leads you to believe most customers don't have it working. Customers who want to use it do so without issue for the most part. There are occasionally gotchas with some emails not being detected though these are usually modified externally (spamassassin is fairly common in terms of adding additional headers which may not meet the standards to allow them to be parsed). But even those emails do not disrupt the overall ability for the system to work, it's just an occasional bounce may not get processed.

We've not had any similar reports of issues and, as I say, ours is functioning fine:

1631292237877.webp

Ultimately the main bit that catches my eye is this:

My system is different from most others of you since I do not get an email but rather an webhook from email provider if email bounces and therefore I have the freedom to craft any kind of email I want based on the webhook I get then to be sent to the xenforo automatic email bounce handler.

This isn't a set up I've necessarily heard of before or recall others here talking about and certainly not something we've tested ourselves.

If you can provide more details about the setup then please do let us know but it's not something we'll be targeting for a bug fix at the moment as it may require significant breaking changes so please feel free to create a suggestion thread and we'll keep it in mind for the future.

Via that suggestion if you can provide as many details as possible such as email provider, how the webhook works, etc. we might be able to set up something similar with a view to supporting it in the future.
 
Okay. Now in this thread I have seen first evidence that anbybody has it working. I tried to search this issue on this forum and all I could find is people asking questions and not getting any answers at all and several other people saying that they cannot get it to work. So there definately are people who have tried and not got it working.

About my setup I am using zeptomail as my email provider as I found their pricing to be much more attractive than for example postmarkapp
zeptomail does not send emails at all for bounces as far as I understand and webhooks is their only supported method of getting the bounce information.
I am currently processing the webhook with https://webhook.site service as that was something I could cook up in matter of hours into working.

But I might be very interested to if xenforo could process the webhook natively and I believe that could be a very useful configuration for many others as well and in the future I could imagine many other email providers also could start offering webhooks as that is a robust and professional solution to a problem that is currently served with the emails as a very nonsatisfactory hacky kind of solution all around.

Their example data structure that zeptomail sends in the webhook is:
{
"event_name": [
"hardbounce"
],
"event_message": [
{
"email_info": {
"email_reference": "13ef.29be9bd5dc4d0f0b.m1.b45dcac0-ebac-11eb-8ab6-525400b65433.17ad337516c@zillium.com",
"is_smtp_trigger": false,
"subject": "webhook test email",
"bounce_address": "webhooktest@zillium.com",
"from": {
"address": "webhooktest@zillium.com",
"name": "webhooktest"
},
"to": [
{
"email_address": {
"address": "bouncerecipient@zillium.com"
}
},
{
"email_address": {
"address": "testrecipient@zillium.com"
}
}
],
"tag": "unknown",
"processed_time": "2021-07-23T11:54:15Z",
"object": "email"
},
"event_data": [
{
"details": [
{
"reason": "relaying-issues",
"bounced_recipient": "bouncerecipient@zillium.com",
"time": "2021-07-23T11:54:15Z",
"diagnostic_message": "bad-mailbox"
}
],
"object": "hardbounce"
}
],
"request_id": "13ef.29be9bd5dc4d0f0b.m1.b45dcac0-ebac-11eb-8ab6-525400b65433.17ad337516c"
}
],
"mailagent_key": "13ef.29be9bd5dc4d0f0b.683ef94c9f44433f",
"webhook_request_id": "13ef.29be9bd5dc4d0f0b.w1.b45df1d1-ebac-11eb-8ab6-525400b65433.17ad337516d"
}

------------------

{
"event_name": [
"softbounce"
],
"event_message": [
{
"email_info": {
"email_reference": "13ef.29be9bd5dc4d0f0b.m1.457ee4c0-eba4-11eb-8ab6-525400b65433.17ad3000d0c@zillium.com",
"is_smtp_trigger": false,
"subject": "webhook test email",
"bounce_address": "webhooktest@zillium.com",
"from": {
"address": "webhooktest@zillium.com",
"name": "webhooktest"
},
"to": [
{
"email_address": {
"address": "bouncerecipient@zillium.com"
}
},
{
"email_address": {
"address": "testrecipient@zillium.com"
}
}
],
"tag": "unknown",
"processed_time": "2021-07-23T10:53:53Z",
"object": "email"
},
"event_data": [
{
"details": [
{
"reason": "relaying-issues",
"bounced_recipient": "bouncerecipient@zillium.com",
"time": "2021-07-23T10:53:53Z",
"diagnostic_message": "policy-related"
}
],
"object": "softbounce"
}
],
"request_id": "13ef.29be9bd5dc4d0f0b.m1.457ee4c0-eba4-11eb-8ab6-525400b65433.17ad3000d0c"
}
],
"mailagent_key": "13ef.29be9bd5dc4d0f0b.683ef94c9f44433f",
"webhook_request_id": "13ef.29be9bd5dc4d0f0b.w1.457f32e0-eba4-11eb-8ab6-525400b65433.17ad3000d0e"
}
 
Okay. Now in this thread I have seen first evidence that anbybody has it working. I tried to search this issue on this forum and all I could find is people asking questions and not getting any answers at all and several other people saying that they cannot get it to work. So there definately are people who have tried and not got it working.
That's not really surprising. People post here when they need help with something. That's not an indicator that a feature doesn't work for everyone.

The range of issues can be everything from misconfigured mail servers to incorrect login details to firewalls - in other words generally the issues are external to XF.

zeptomail does not send emails at all for bounces as far as I understand and webhooks is their only supported method of getting the bounce information.
I am currently processing the webhook with https://webhook.site service as that was something I could cook up in matter of hours into working.

But I might be very interested to if xenforo could process the webhook natively and I believe that could be a very useful configuration for many others as well and in the future I could imagine many other email providers also could start offering webhooks as that is a robust and professional solution to a problem that is currently served with the emails as a very nonsatisfactory hacky kind of solution all around.
Definitely something we can consider in the future, or in the meantime a developer may be able to create an add-on to help you.
 
Last edited:
It works well here, and automatically sets someone to BOUNCED status (forces them to enter new email) when there is a "hard bounce". The soft ones are for warning only, in the log. I havent verified that the unsubscribe works, but I would assume so.
 
We have a concept of having too many soft bounces within a period of time and taking action too. This can be configured with the emailSoftBounceThreshold option.
 
Back
Top Bottom