I’m currently engaged in a project where I need to craft responsive HTML emails for clients. My main hurdle is ensuring that these emails display correctly across different devices. Could anyone advise on the best practices for testing the responsiveness of HTML emails?
1 Like
It’s not just devices, it’s also email clients (e.g. Outlook, Thunderbird, Gmail, iPad email, Samsung email, etc, etc, etc).
There is no generally-accepted standard for html rendering in an email client. This means you’d need to test on every email client package for every operating system being used to retrieve those emails. (A quick internet search on this topic shows what a mess the current situation is.)
Best of luck to you.
1 Like
Hi Lukas, I suggest trying out Mailtrap as a mail server for testing purposes because it offers a straightforward approach to sending HTML emails and provides the features needed for your task.
Below, I’ll share a few Flask code examples that demonstrate how to send an email using the Mailtrap server.
```python
from django.core.mail import EmailMessage
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# Configure your email settings in Django settings.py
# EMAIL_HOST = 'smtp.gmail.com'
# EMAIL_PORT = 587
# EMAIL_HOST_USER = 'your-email@gmail.com'
# EMAIL_HOST_PASSWORD = 'your-email-password'
# EMAIL_USE_TLS = True
@csrf_exempt
def send_email(request):
if request.method == 'POST':
smtp_server = 'sandbox.smtp.mailtrap.io'
smtp_port = 587
smtp_user = 'username' # Replace with your MAILTRAP username
smtp_password = 'password' # Replace with your MAILTRAP password
subject = 'New Form Submission'
body = 'This is the form submission content'
from_email = 'sender@example.com' # Replace with your sender email
to_email = ['receiver@example.com'] # Replace with your receiver email list
try:
email = EmailMessage(
subject,
body,
from_email,
to_email
)
email.send()
return HttpResponse("Email sent successfully!")
except Exception as e:
return HttpResponse(f"Error: {str(e)}")
else:
return HttpResponse("This endpoint only accepts POST requests.")