title: how to send mail with attachment which is byte array with java mail sender?
body: <p>I want to send an email using java mail sender.I have byte array which I should send as a mail attachment.I have tried multiple ways but the attachment that is coming is not in readable format.Its coming as bytes.Below is the code I have tried.</p>
  
  <pre><code>public void sendMailWithAttachments(EmailContent emailContent,
              byte[] attachment) {
          try{
              MimeMessage mimeMessage = emailSender.createMimeMessage();
              MimeMessageHelper mimeMessageHelper = new 
               MimeMessageHelper(mimeMessage, true);
  
              mimeMessageHelper.setTo(emailContent.getTo());
              mimeMessageHelper.setFrom(emailContent.getFrom());
              mimeMessageHelper.setCc(emailContent.getCc());
              mimeMessageHelper.setSubject(emailContent.getSubject());
  
  
                  final InputStreamSource attachmentSource = new ByteArrayResource(attachment);
                  DataSource dataSource = new ByteArrayDataSource(attachment, "application/pdf");
                  mimeMessageHelper.addAttachment("testattachment", dataSource);
  
  
  
              emailSender.send(mimeMessageHelper.getMimeMessage());
              emailContent.setStatus(true);
          }catch(Exception e){    
              e.printstacktrace
          }
  </code></pre>