Generating emails and avoiding ATP problems
Posted: Mon 26 Aug 2019 13:20
Some email products now make use of Advanced Threat Protection (ATP), which has the potential to thoroughly mangle any server-generated emails that you send. Essentially, it replaces any URLs in your message with so-called "safe links", which can render your emails illegible. Here is an outline of the problem and how to avoid it. Thanks to Gary Douthwaite for alerting me to this problem.
If you are in the habit (as I am) of using server-generated plain-text emails that contain URLs (or more specifically, web site addresses) then you might find that certain email packages - Outlook, gmail etc - replace your compact url, like, e.g. http://hidden.earth, with a much longer and illegible URL that directs the reader to a site that checks the email address for validity. As far as I can determine, the algorithm for this is
although that does not allow for URLs that might span more than one line. To encapsulate the text, do something like ...
I am in the process of applying these changes across all the sites that I maintain. I use a single custom function to send email, so its relatively easy to say "if the email does not contain any MIME info then add a MIME type of HTML, encapsulate in <pre> tags and parse for URLs". The problem occurs, for me, if the message is already a multipart MIME message. That's trickier to handle and probably means (for me) "manually" modifying the message when it is generated.
hope this helps
If you are in the habit (as I am) of using server-generated plain-text emails that contain URLs (or more specifically, web site addresses) then you might find that certain email packages - Outlook, gmail etc - replace your compact url, like, e.g. http://hidden.earth, with a much longer and illegible URL that directs the reader to a site that checks the email address for validity. As far as I can determine, the algorithm for this is
- If the email is in plain text, parse it for http addresses and replace them
- if the email is in HTML then parse and replace only the href attribute of the <a> tag
- add a MIME header for HTML content (how to do that is not covered in this post)
- encapsulate the content in <pre> tags, possibly adding a style setting for the font as well (or it may default to Courier (yuk!) in your customer's email viewer
- If the email is in plain text, parse it for http addresses and display them as clickable links
- if the email is in HTML then leave it to the HTML renderer to do this task
Code: Select all
function parse_for_URLs($message) // returns a modified $message
{
// in a supposed plain-text email, replace http addresses with <a> tags
return preg_replace('/(http.*?)(?=[\.,;\'\"]?\s)/', '<a href="$1">$1</a>', $message);
}
Code: Select all
function add_HTML_wrapper($message) // returns a modified $message
{
$message_top = <<<EOT
<!--This message requires an HTML text viewer-->
<pre style="font-family: Consolas, 'DejaVu Sans Mono', 'Lucida Console', 'Andale Mono', monospace">
EOT;
$message_tail = "</pre>\n";
$message = $message_top . $message . $message_tail;
return $message;
}
hope this helps