When we attach an image to an email or embed it using an HTML <img>
tag, most email clients display a warning or notification when the recipient opens the message. This happens because the email attempts to load the image from a remote source, which the email client considers a potential privacy risk.
As a result:
- The email content doesn’t display properly until the recipient explicitly grants permission to load external resources.
- Many users either ignore this permission request or delete the email altogether, thinking it's suspicious.
To overcome this issue, there's a highly effective strategy:
✅ Base64 Embedded HTML
With Base64 embedded HTML, the image is encoded into a long string of text and directly embedded within the email content. Since the image is already included in the body of the email, there's no need to fetch it from any external server. This approach ensures:
- The content is displayed immediately without any warnings.
- The user experience is smooth and seamless.
🛠️ How to Embed Images Using Base64
1) Convert the Image to Base64 Using Windows CMD or PowerShell
Run the following command in your Command Prompt (CMD):
For a .png
image:
powershell -command "$bytes = [System.IO.File]::ReadAllBytes('C:\Users\User Name\Downloads\logo.png'); $b64 = [Convert]::ToBase64String($bytes); Set-Content -Path 'C:\Users\User Name\Downloads\logo.png.base64.txt' -Value $b64"
For a .jpg
image:
powershell -command "$bytes = [System.IO.File]::ReadAllBytes('C:\Users\User Name\Downloads\logo.jpg'); $b64 = [Convert]::ToBase64String($bytes); Set-Content -Path 'C:\Users\User Name\Downloads\logo.jpg.base64.txt' -Value $b64"
This will generate a text file containing a long string of encoded text representing the image.
2) Determine the MIME Type Based on File Extension
Use the correct MIME type based on your image format:
Image Type | MIME for HTML Tag |
---|---|
.png | data:image/png;base64,... |
.jpg / .jpeg | data:image/jpeg;base64,... |
.gif | data:image/gif;base64,... |
.webp | data:image/webp;base64,... |
3) Embed the Image in HTML
For PNG:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." />
For JPG:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..." />
You can copy the entire Base64 string and paste it into the src
attribute as shown above.
✅ Conclusion
By using this simple yet powerful Base64 embedding technique, you can ensure your images are delivered cleanly to recipients' inboxes without triggering warnings or requiring additional permissions.
It’s an excellent way to improve the visual consistency of your email communications and guarantee better engagement from your audience.
Post a Comment
Post a Comment