title: How to attach base64 image in mail to JavaMail and MimeMessageHelper?
body: <p>I am trying to send the Mime email with an image attachment but do know how to do this. I tried the online solution but did not work. I will get the encoded image and need to decode and attach in the mail. This is my code</p>
  
  <pre><code>public class SendEmail{
  
  public static void main( String[] args ) throws javax.mail.MessagingException, IOException
  {  
  
      String value= "Wyk+HjAxHTAyNzg3MDUdODQwHTAxOR0wMDAwMDAwMDAwMDAwMDAd" +
              "RkRFQh0wMDAwMDAwHTA0MB0dMS8xHTUwLjVMQh1OHVcgMzR0aCBTdHJlZXQdQ" +
              "XVzdGluHVRYHSAeMDYdMTBaR0QwMDQdMTFaUmVjaXBpZW50IENvbXBhbnkgTmFt" +
              "ZR0xMlo5MDEyNjM3OTA2HTE0WioqVEVTVCBMQUJFTCAtIERPIE5PVCBTSElQKio" +
              "dMjNaTh0yMlocWR0yMFogHDAdMjZaNjEzMxwdHgQ=";     
  
        JavaMailSender mailSender = getJavaMailSender();
  
      MimeMessage mimeMessage = mailSender.createMimeMessage();
      MimeMessageHelper helper;
      Map&lt;String,Object&gt; map = new HashMap&lt;&gt;();
  
      try{
          helper = new MimeMessageHelper(mimeMessage, true, "utf-8");
          String sendTo = "abc@gmail.com";
          String htmlMsg = "&lt;h1&gt; hello &lt;/h1&gt;";
  
          mimeMessage.setContent(htmlMsg, "text/html");
  
          // add attachment encode in base64
          byte[] decodedImg  Base64.decodeBase64(value);
          // dont know how to attache the decode img 
  
  
          helper.setTo(sendTo);
          helper.setSubject("Subject");
          mailSender.send(mimeMessage);
      } catch (MessagingException e) {
          e.printStackTrace();
      }
  
  
  
  }
  </code></pre>