![]() |
![]() |
![]() |
![]() |
![]() |
Accueil |
Downloads |
private void
saveImage(int[][] imgRGB, String filename) { try { bimg = new BufferedImage(imgRGB.length, imgRGB[0].length, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < imgRGB.length; i++) for (int j = 0; j < imgRGB[0].length; j++) bimg.setRGB(i, j, imgRGB[i][j]); try { System.out.println("Save image : "+ filename); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename)); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimg); int quality = 100; quality = Math.max(0, Math.min(quality, 100)); param.setQuality((float) quality / 100.0f, false); encoder.setJPEGEncodeParam(param); encoder.encode(bimg); } catch (Exception e) { e.printStackTrace(); } } |
Properties
props = System.getProperties(); props.put("mail.smtp.host", smtpServer); Session session = Session.getInstance(props, null); |
private MimeMessage
getAttachementMessage( Session session, String from, String to, String subject, String body, String filename) { MimeMessage msg = null; // create a message try { msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setText(body); // create and fill the first message part if (filename != null) { File f = new File(filename); if (f.exists()) { MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(filename); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); } } msg.setSentDate(new Date()); } catch (Exception e) { e.printStackTrace(); } return msg; } |
public void send(String
smtpServer, String to, String from, String subject, String body, String
filename) { ... Message msg = getAttachementMessage(session, from, to, subject, body, filename); if (msg != null) try { Transport.send(msg); } catch (Exception e) { e.printStackTrace(); } ... } |
insa.mail.sender=*******@insa-lyon.fr
// l'adresse de l'expediteur insa.mail.receiver=*******@insa-lyon.fr // l'adresse du destinatiare insa.mail.smtp=mail.insa-lyon.fr // le serveur SMTP à utiliser insa.mail.tmpfile=******.jpg // nom du fichier temporaire pour sauvegarder l'image ... |