DEV Community

Alex Gravely
Alex Gravely

Posted on • Edited on • Originally published at blog.antitcb.dev

1

ColdFusion - Display Names for CFMail

I had an interesting client request come in last week, they wanted the ability to have prettier names show up for their From: email addresses. E.G, having the from address be their company name, rather than displaying in inboxes as info@company.com. Surely, this would be a simple thing to accommodate, and ColdFusion definitely supported this out of the box, but I did run into a hiccup and hopefully I can save someone else the time I spent trying to figure this all out!

Generally when you're using the CFMail tag, you're using email addresses as is. If you're just using this tag as is, then you can follow this format to get display names to show up for the email.

<!--- Would show the email as from "Alex Gravely" in your inbox --->
<cfmail from='Alex Gravely<alex@example.com>' />

<!--- If you have special characters, you can wrap the display name in double quotes --->
<cfmail from='"Alex Jr. @ Freelance"<alex@example.com>' />
Enter fullscreen mode Exit fullscreen mode

Now here's where my pitfall was: we use a customized CFMail tag that ends up using C#'s System.Net.Mail.SmtpClient, and as part of that custom tag's validation, we use the IsValid function for validating the email format. Surprisingly enough, trying to do this display name format actually fails this function's validation, despite working properly in the CFMail tag.

If you do want validation support for this format as well, this regex pattern does the job: (?:"?([^"]*)"?\s)?(?:<?(.+@[^>]+)>?)/gi

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay