简体   繁体   中英

How do I center an image in HTML sent through javamail?

I have sourced and passed the images to the mail body using

            messageBodyPart = new MimeBodyPart();
            DataSource fds1 = new FileDataSource( "images\\IG.png");
            messageBodyPart.setDataHandler(new DataHandler(fds1));
            messageBodyPart.setHeader("Content-ID", "<IG>");
            multipart.addBodyPart(messageBodyPart);


            messageBodyPart = new MimeBodyPart();
            DataSource fds2 = new FileDataSource( "images\\Twitter.png");
            messageBodyPart.setDataHandler(new DataHandler(fds2));
            messageBodyPart.setHeader("Content-ID", "<Twitter>");
            multipart.addBodyPart(messageBodyPart);


            messageBodyPart = new MimeBodyPart();
            DataSource fds3 = new FileDataSource( "images\\web.png");
            messageBodyPart.setDataHandler(new DataHandler(fds3));
            messageBodyPart.setHeader("Content-ID", "<web>");
            multipart.addBodyPart(messageBodyPart);

and have applied a style to center the image. It works well when viewed with a web browser, but the images are moved to the left when the email is sent. The circle style applied to the images is applied when viewed from a browser and in Gmail.

Another problem is that an image I source from Figma in the HTML template displays as an attachment, how can I make it display as an image instead of an attachment?

As far as I know, e-mails do not support full CSS and the only way to center things in e-mail clients are with tables. Something like:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td align="center">
        <img ... />
    </td>
</tr>
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM