I'm creating a email generator using React. I'm rendering tables (since that's what an email must have).
In most email browsers the email looks decent, except in Outlook which expands the images and ruins the layout.
Here is the specific component that renders the images:
const Ad = ({ image, link, hasDivider, styles = localStyles }) => (
<>
<Grid.Row className={styles.container}>
<a href={link}>
<span
dangerouslySetInnerHTML={{
__html: `
<!--[if mso]>
<table width="100%">
<tr>
<td>
<img width="100%" src=${image}
alt="ad" style="text-align: right; width: 100%; border: 0;
text-decoration:none;
vertical-align: baseline;">
</td>
</tr>
</table>
<div style="display:none">
<![endif]-->`
}}
/>
<Img className={styles.image} src={image} alt="ad" />
<span
dangerouslySetInnerHTML={{
__html: `
<!--[if mso]>
</div>
<![endif]-->
`
}}
/>
</a>
</Grid.Row>
{hasDivider && (
<Grid.Row>
<Divider />
</Grid.Row>
)}
</>
)
Img
component:
const Img = ({ src, alt, className, styles = localStyles, style = {} }) => {
return (
<img
src={src}
alt={alt}
style={style}
className={cx(styles.img, className)}
/>
)
}
I'm using "email conditionals" for this which kind of works in more modern Outlook versions.