Tutorial•4 min read

Accessible Transactional Emails Developers Should Ship

Learn how to build and send accessible transactional emails using semantic HTML, proper alt text, and good color contrast. Ensure your critical communications reach and are understood by all users with Piisend.

Accessible Transactional Emails Developers Should Ship

Section 1

Why Email Accessibility is Crucial for Developers

As developers, we often focus on functionality and delivery, but ensuring our transactional emails are accessible is equally vital. Accessible emails benefit everyone, including users with visual impairments who rely on screen readers, or those with cognitive disabilities who need clear, well-structured content. Prioritizing accessibility not only broadens your audience but also demonstrates a commitment to inclusive design, potentially avoiding legal issues and enhancing user trust. It's about making sure your critical messages, like password resets or order confirmations, are universally understood.

Section 2

Crafting Semantic HTML and Image Alt Text

The foundation of an accessible email lies in its HTML structure. Using semantic HTML tags like <h1>, <p>, <ul>, and <a> instead of generic <div> elements helps screen readers interpret the content's hierarchy and purpose. For images, always include a descriptive alt attribute. This text is read aloud by screen readers, providing context for users who cannot see the image. If an image is purely decorative, an empty alt="" attribute is appropriate to prevent screen readers from announcing it. Piisend allows you to send rich HTML content directly, giving you full control over your email's structure and accessibility features.

bash
1curl -X POST https://api.piisend.com/api/v1/emails \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "to": ["user@example.com"],
6 "subject": "Your Order Confirmation - Accessible Example",
7 "html": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Order Confirmation</title>\n</head>\n<body>\n <h1>Order #12345 Confirmed!</h1>\n <img src=\"https://example.com/logo.png\" alt=\"Piisend Company Logo\" width=\"100\">\n <p>Dear Customer,</p>\n <p>Thank you for your recent purchase. Your order has been successfully placed and will be shipped soon.</p>\n <ul>\n <li>Item 1: $10.00</li>\n <li>Item 2: $20.00</li>\n </ul>\n <p>If you have any questions, please <a href=\"https://piisend.com/support\">contact our support team</a>.</p>\n</body>\n</html>"
8 }'

Section 3

Optimizing Readability with Color Contrast and Responsiveness

Color contrast is a critical accessibility factor. Ensure there's sufficient contrast between text and background colors to make your content readable for users with low vision or color blindness. Tools like WebAIM's Contrast Checker can help you meet WCAG guidelines. Additionally, responsive design is paramount for emails, as users access them on a wide array of devices. Use fluid layouts, relative units, and media queries to ensure your emails adapt gracefully to different screen sizes. Piisend's API doesn't interfere with your HTML/CSS, allowing you to implement these design principles directly within your email content.

python
1import requests
2import json
3
4API_KEY = "YOUR_API_KEY"
5
6html_content = """
7<!DOCTYPE html>
8<html lang="en">
9<head>
10 <meta charset="UTF-8">
11 <meta name="viewport" content="width=device-width, initial-scale=1.0">
12 <title>Important Update</title>
13 <style>
14 body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f4f4f4; color: #333; }
15 .container { max-width: 600px; margin: 0 auto; background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
16 h1 { color: #0056b3; }
17 p { line-height: 1.6; }
18 a { color: #007bff; text-decoration: underline; }
19 /* Ensure good contrast: text #333 on background #fff */
20 /* Responsive adjustments */
21 @media only screen and (max-width: 600px) {
22 .container { padding: 15px; }
23 }
24 </style>
25</head>
26<body>
27 <div class="container">
28 <h1>Important Account Update</h1>
29 <p>Dear Valued Customer,</p>
30 <p>We have an important update regarding your account. Please review the details below.</p>
31 <p>For more information, visit our <a href="https://piisend.com/faq">FAQ page</a>.</p>
32 </div>
33</body>
34</html>
35"""
36
37headers = {
38 "Authorization": f"Bearer {API_KEY}",
39 "Content-Type": "application/json"
40}
41
42payload = {
43 "to": ["recipient@example.com"],
44 "subject": "Your Account Update - Readability Focus",
45 "html": html_content
46}
47
48response = requests.post("https://api.piisend.com/api/v1/emails", headers=headers, data=json.dumps(payload))
49
50print(f"Status Code: {response.status_code}")
51print(f"Response: {response.json()}")

Section 4

Integrating Accessibility into Your Piisend Workflow

Piisend's email API for developers is designed to be flexible, allowing you to send any valid HTML content. This means you can fully implement all accessibility best practices directly within your email templates or dynamically generated HTML. For consistency, consider creating a set of accessible base templates within Piisend that your team can reuse. These templates can incorporate semantic HTML, proper alt text, and tested color contrasts, ensuring every transactional email you send is accessible by default. By integrating accessibility from the start, you build a more robust and inclusive communication strategy.

javascript
1const fetch = require('node-fetch');
2
3const PIISEND_API_KEY = 'YOUR_API_KEY';
4
5const accessibleHtml = `
6<!DOCTYPE html>
7<html lang="en">
8<head>
9 <meta charset="UTF-8">
10 <meta name="viewport" content="width=device-width, initial-scale=1.0">
11 <title>Password Reset</title>
12 <style>
13 body { font-family: sans-serif; line-height: 1.5; margin: 0; padding: 20px; background-color: #f9f9f9; color: #333; }
14 .wrapper { max-width: 600px; margin: 0 auto; background-color: #ffffff; padding: 25px; border-radius: 8px; border: 1px solid #ddd; }
15 h1 { color: #1a73e8; font-size: 24px; margin-bottom: 20px; }
16 p { margin-bottom: 15px; }
17 .button { display: inline-block; background-color: #1a73e8; color: #ffffff; padding: 12px 24px; text-decoration: none; border-radius: 5px; font-weight: bold; }
18 .footer { margin-top: 30px; font-size: 12px; color: #777; text-align: center; }
19 </style>
20</head>
21<body>
22 <div class="wrapper" role="main">
23 <h1>Password Reset Request</h1>
24 <p>Hello,</p>
25 <p>We received a request to reset your password. If you did not make this request, please ignore this email.</p>
26 <p>To reset your password, click the button below:</p>
27 <p><a href="https://your-app.com/reset-password?token=YOUR_RESET_TOKEN" class="button">Reset Your Password</a></p>
28 <p>This link will expire in 24 hours.</p>
29 <div class="footer">
30 <p>&copy; 2024 Your Company. All rights reserved.</p>
31 </div>
32 </div>
33</body>
34</html>
35`;
36
37async function sendAccessibleEmail() {
38 try {
39 const response = await fetch('https://api.piisend.com/api/v1/emails', {
40 method: 'POST',
41 headers: {
42 'Authorization': `Bearer ${PIISEND_API_KEY}`,
43 'Content-Type': 'application/json'
44 },
45 body: JSON.stringify({
46 to: ['user@example.com'],
47 subject: 'Your Password Reset Link - Accessible',
48 html: accessibleHtml
49 })
50 });
51
52 const data = await response.json();
53 console.log('Email sent successfully:', data);
54 } catch (error) {
55 console.error('Error sending email:', error);
56 }
57}
58
59sendAccessibleEmail();

Start sending

Ship transactional email in minutes

Create an API key, verify a domain, and send your first message with Piisend.