Send genarate qr code image to email

I can use jsp servlet send local image to email already but I can't send result image from generate qr code to email. I use zxing for create qr code and I must send result image qr code to email.

String qrtext = request.getParameter("qrtext");

ByteArrayOutputStream out = QRCode.from(qrtext).to(ImageType.JPG).stream();

response.setContentType("image/jpg");

response.setContentLength(out.size());

OutputStream outStream = response.getOutputStream();

outStream.write(out.toByteArray());

code set local image send to email.

MimeMultipart multipart = new MimeMultipart("related");

messageBodyPart = new MimeBodyPart();

DataSource fds = new FileDataSource("D:/123.jpg");

messageBodyPart.setDataHandler(new DataHandler(fds));

messageBodyPart.setHeader("Content-ID", "");

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

Transport.send(message);

System.out.println("Sent message successfully....");

I try change DataSource fds = new FileDataSource("out.toByteArray()");

but it not working....

Read More »

By: StackOverFlow - Wednesday, 14 March

Related Posts

  • Older News
  • GMail not returning bounced email StackOverFlow (3 days ago) - We have a Java application that sends email through our corporate Google provided email accounts. It works fine in most cases, but when we have a wrong email address we...