title: Send QRcode to email using java
body: <p>Can I send QRcode to email directly without any local storage work using java?The code below generates QRcode. </p>
  
  <pre><code>public static void createQRCode(String qrCodeData, String filePath,
  String charset, Map hintMap, int qrCodeheight, int qrCodewidth)
  throws WriterException, IOException {
  BitMatrix matrix = new MultiFormatWriter().encode(
      new String(qrCodeData.getBytes(charset), charset),
      BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap);
  MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
      .lastIndexOf('.') + 1), new File(filePath));
  System.out.println("QR code encoded");
  }
  
  public static String readQRCode(String filePath, String charset, Map hintMap)
  throws FileNotFoundException, IOException, NotFoundException {
  BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
      new BufferedImageLuminanceSource(
              ImageIO.read(new     FileInputStream(filePath)))));
  Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap,
      hintMap);
  return qrCodeResult.getText();
  }
  </code></pre>
  
  <p>I want to attach this above generated QR to this below code in body section without storing it locally. I'm using eclipse Mars.. Please do help me out</p>
  
  <pre><code>String from = USER_NAME;
  String pass = PASSWORD;
  String[] to = {RECIPIENT};
  String subject = "Java mail example";
  String body= "hi this is tetsting mail!";
  
  
  Properties props = System.getProperties();
  String host = "smtp.gmail.com";
  
  props.put("mail.smtp.starttls.enable", "true");
  
  props.put("mail.smtp.host", host);
  props.put("mail.smtp.user", from);
  props.put("mail.smtp.password", pass);
  props.put("mail.smtp.port", "587");
  props.put("mail.smtp.auth", "true");
  
  
  Session session = Session.getDefaultInstance(props, null);
  MimeMessage message = new MimeMessage(session);
  
  try {
  
  
  message.setFrom(new InternetAddress(from));
  InternetAddress[] toAddress = new InternetAddress[to.length];
  
  // To get the array of addresses
  for( int i = 0; i &lt; to.length; i++ ) {
     toAddress[i] = new InternetAddress(to[i]);
  }
  
  for( int i = 0; i &lt; toAddress.length; i++) {
     message.addRecipient(Message.RecipientType.TO, toAddress[i]);
  }
  
  message.setSubject(subject);
  message.setText(body, "UTF-8", "html");
  
  Transport transport = session.getTransport("smtp");
  transport.connect(host, from, pass);
  transport.sendMessage(message, message.getAllRecipients());
  transport.close();
  System.out.println("Email Sent successfully");
  
  }
  catch (AddressException ae) {
  ae.printStackTrace();
  }
  catch (MessagingException me) {
  me.printStackTrace();
  }
  }
  </code></pre>