You have jane@stripe.com and want to show Stripe's logo next to her name. The best source for that logo is one most developers have never heard of: BIMI.
What BIMI is
BIMI (Brand Indicators for Message Identification) is a standard that lets a domain publish its official logo so email clients can show it next to messages. The logo lives in a DNS TXT record:
default._bimi.example.com. TXT "v=BIMI1; l=https://example.com/logo.svg; a=https://example.com/vmc.pem"
l=points to the logo, a square SVG in the restricted "SVG Tiny Portable/Secure" profile.a=optionally points to a certificate (a VMC or CMC) that proves the brand owns the mark. Gmail requires it to show the logo.- Mailbox providers only honor BIMI when the domain enforces DMARC (
p=quarantineorp=reject).
Those requirements are why BIMI logos are good: a company that publishes one has gone to the trouble of setting up email authentication, and often of certifying its trademark. The logo is square, vector, and official.
Reading it yourself
- Look up the TXT record at
default._bimi.<domain>. In a Worker or browser, a DNS-over-HTTPS endpoint works:https://cloudflare-dns.com/dns-query?name=default._bimi.stripe.com&type=TXTwithaccept: application/dns-json. - Parse
l=out of the record. - Fetch the SVG, check it really is an image, and serve or cache it.
Most domains do not publish BIMI, so you also need a fallback for the rest.
One URL that does it, with fallbacks
<img src="https://avatarsapi.com/domain/stripe.com?size=64" alt="">
/domain/:domain walks a Ladder: BIMI first, then DuckDuckGo and Google favicons if there is no BIMI record. Whatever it finds is fetched and validated as a real image before it is served. If nothing usable exists, you get a 404 with "code": "ENOTFOUND".
For a work email, /email/:address goes one step further. It checks the person first (Gravatar and GitHub, raced), and only then falls back to the domain's BIMI logo:
<img src="https://avatarsapi.com/email/jane@stripe.com?size=64" alt="">
That gives you a face when the person has one and a company logo when they do not, from a single src.
Related
- Favicon APIs compared: what happens when there is no BIMI record.
- Clearbit Logo API alternatives: when you need a full logo database.
https://avatarsapi.com/github/torvalds in an <img src>. No key, no signup. Read the docs or create a Project.