Apache Commons Email Base64 Image

Asked

Viewed 97 times

0

I have software to send emails that use apache Commons email to send html emails, I also have in the database a string that represents an image Base64 example data:image/png;base64,iVBORw0K ....

I tried to use the html img tag to send this email but it didn’t help, I found some tutorials that teach using an image of the internet like this for example. https://commons.apache.org/proper/commons-email/userguide.html

I wonder if anyone can help me to convert this string into image, attach it to the email and use it in the body of the email using the apache api with email

Method to send the email is as follows

public String enviarEmail(Email mail) throws Exception {
        try {
                HtmlEmail email = new HtmlEmail();
                email.setCharset(EmailConstants.UTF_8);
                email.setHostName("myHost");
                email.setStartTLSEnabled(true);
                email.setSmtpPort(99);
                String[] destinatarios =(String[])mail.getLstDestinatarios().toArray(new String[0]);
                email.addBcc(destinatarios);
                email.setFrom(mail.getRemetente());                 
                email.setSubject(mail.getAssunto());
                email.setHtmlMsg(mail.getMensagem());
                email.send();
                return "email enviado com sucesso";
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(e);
        }
  • How is the class that sends e-mail ?

  • Reply at this link: https://stackoverflow.com/questions/23979842/convert-base64-string-to-image

  • You transform your Base64 Array into the same image in the link as in the comment above. A attaches using Emailattachment();

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.