1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
public Message checkMail(String ServeurSNMP,File fichierTemp,String mailingList,String Subject,String content,String typSource,String nomSource){
//.........................
File fichierTemp = null;
Properties props = System.getProperties( );
props.put("mail.smtp.host", ServeurSNMP);
Session session = Session.getDefaultInstance(props, null);
msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("maniolo@free.fr"));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress(mailingList));
msg.setSubject(Subject);
mp = new MimeMultipart();
mbp1 = new MimeBodyPart();
mbp1.setContent(content, "text/plain");
mp.addBodyPart(mbp1);
mbp = new MimeBodyPart();
//je passe en parametre mon fichiertemp de type File
FileDataSource source = new FileDataSource(fichierTemp);
mbp.setDataHandler(new DataHandler(source));
mbp.setFileName(nomSource);
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
//..............................;
et dans la classe principale :
Document docPdf = null;
PdfWriter pdfWriter = null;
File temp = File.createTempFile("monfichier",".pdf");
pdfWriter = PdfWriter.getInstance(docPdf, new FileOutputStream(temp));
docPdf.open();
//.......construction du pdf...............
//puis on ferme bien tout et on appel la methode de la classe mail
docPdf.close();
pdfWriter.close();
checkMail.checkMail(ServeurSNMP, temp,mailingList, Subject, content, typSource ,nomSource);
temp.deleteOnExit(); |
Partager