Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard way to detect mobile mail client?

This question is similar to "Standard way to detect mobile browsers in a web application based on the http request" except for mail clients. For instance, if an email message is opened on the built-in iPhone mail client it will display a version of the message specially formatted for the iPhone. If opened on an tablet or desktop it will display as the complete, full-size version of the email. This is similar in principle to web sites that have mobile-friendly versions of the site that load automatically by detecting the user-agent - but for email clients.

So - is it possible to detect the mail client being used to open an email and format the message accordingly? Perhaps a way to detect the screen resolution?

like image 609
leepowers Avatar asked Mar 15 '11 18:03

leepowers


People also ask

How do I know if a site is open in mobile or desktop?

We can use the CSS media queries to check whether the website is opened inside a web browser or a mobile browser. This information can be fetched using the min-width and the max-width of the webpage.

How to check if device is mobile in JavaScript?

matchMedia() The Window interface's matchMedia() method returns a new MediaQueryList object that can then be used to determine if the document matches the media query string. For example, a device whose screen width does not exceed 768px is considered a mobile device: const isMobile = window.

How to detect device JavaScript?

You can use JavaScript window. matchMedia() method to detect a mobile device based on the CSS media query. You may also use navigator. userAgentData.


2 Answers

You can try to apply @media css queries that target specific browsers like mobile devices. There is a good introduction on the campaignmonitor help website but be aware, it probably is only supported in a hand full of browsers and devices, iOS being on of them luckily :)

Basically you are defining css styles that target specific screen widths so that you can optimize your email for limited screen space.

@media only screen and (max-device-width: 480px) { ... }

When talking really detection and displaying a totally different email, that's really impossible since you are talking about javascript there and that's not done in emails and probably won't even work in 99% of all email clients. But you can go a loooong way with @media queries.

like image 159
ChrisR Avatar answered Sep 22 '22 09:09

ChrisR


I think the best solution is using responsive web design techniques. So my suggestion would be a fluid email layout that would adjust based on the size of the cellphone screen.

Here is an example: http://stylecampaign.com/blog/?p=85

Note: Writing markup for email is a whole different beast than the browser. Here are a few guides worth looking at:

http://articles.sitepoint.com/article/code-html-email-newsletters/

http://www.mailchimp.com/resources/guides/email-marketing-field-guide/

like image 42
Tom Avatar answered Sep 21 '22 09:09

Tom