texerasmo
24-02-2006, 16:22
L'email me la invia anche con l'allegato ma ho un pb 
Non riesco a far interpretare il messaggio in html.
 
public String sendAllegato(String host, String from, String to, String subject, String mes, String mimetype,String filename) {
String errore="";
try{
            
File f=new File(filename);
            
// Get system properties
Properties props = System.getProperties();
            
// Setup mail server
props.put("mail.smtp.host", host);
            
// Get session
Session session = Session.getDefaultInstance(props, null);
            
// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(subject);
            
// Create the multi-part
Multipart multipart = new MimeMultipart();
            
// Create part one
BodyPart messageBodyPart = new MimeBodyPart();
            
// Fill the message
messageBodyPart.setText(mes);
            
// Add the first part
multipart.addBodyPart(messageBodyPart);
            
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(f);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
            
// Add the second part
multipart.addBodyPart(messageBodyPart);
            
// Put parts in message
message.setContent(multipart);
            
// Send message
Transport.send(message);
System.out.println("Finito");
            
            
}catch(Exception e) {
errore=e.getMessage();
}
return errore;
}
Non riesco a far interpretare il messaggio in html.
public String sendAllegato(String host, String from, String to, String subject, String mes, String mimetype,String filename) {
String errore="";
try{
File f=new File(filename);
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(subject);
// Create the multi-part
Multipart multipart = new MimeMultipart();
// Create part one
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(mes);
// Add the first part
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(f);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
// Add the second part
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send message
Transport.send(message);
System.out.println("Finito");
}catch(Exception e) {
errore=e.getMessage();
}
return errore;
}