Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Email e immagini

    Salve ragazzi... Sto provando a inviare delle email in formato html con java.
    Nelle mail sono contenute delle immagini che io passo con il link assoluto della mia macchina. Il problema è che alla mail non vengono inviate come allegati ma si porta appresso il link della mia macchina locale..

    qualche suggerimento?
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    ti ringrazio!
    solo che funziona per la prima immagine e basta...
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    modifica l'esempio in modo che venga aggiunto un part per ogni file che vuoi allegare..., da me questa funziona

    codice:
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    
    public class HtmlImageExample {
      public static void main (String args[]) throws Exception {
        String host = "tuo.smtp.com";
        String from = "sender@tuosito.com";
        String to = "repicient@altrosito.com";
    /*
     * queste le ho aggiunte per comodità, 
     * vedrai tu come generare o pescare 
     * i percorsi dei file da allegare */
        String basePath = "C:/Documents and Settings/Andrea/Desktop/";
        String[] file = {basePath+"oldpic.jpg", basePath+"nemo.jpg"};
        String[] cids = {"picone", "pictwo"};
    /* anche i cid li puoi generare a caso */
        // Get system properties
        Properties props = System.getProperties();
    
        // Setup mail server
        props.put("mail.smtp.host", host);
    
        // Get session
        Session session = Session.getDefaultInstance(props, null);
    
        // Create the message
        Message message = new MimeMessage(session);
    
        // Fill its headers
        message.setSubject("Final");
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    
        // Create your new message part
        BodyPart messageBodyPart = new MimeBodyPart();
    
        // Set the HTML content, be sure it references the attachment
        String htmlText = "<H1>Hello</H1>";
        for (int i = 0; i < cids.length; i++) {
            htmlText+="
    
    <img src=\"cid:"+cids[i]+"\" /></p>\n";
        }      
    
        // Set the content of the body part
        messageBodyPart.setContent(htmlText, "text/html");
    
        // Create a related multi-part to combine the parts
        MimeMultipart multipart = new MimeMultipart("related");
    
        // Add body part to multipart
        multipart.addBodyPart(messageBodyPart);
    
        
    
        DataSource fds;
        for (int i= 0; i < file.length; i++) {
            // Create part for the image
            messageBodyPart = new MimeBodyPart();
            
            // Fetch the image and associate to part
            fds = new FileDataSource(file[i]);
            
            messageBodyPart.setDataHandler(new DataHandler(fds));
    
            // Add a header to connect to the HTML
            messageBodyPart.setHeader("Content-ID","<"+cids[i]+">");
            
            // Add part to multi-part
            multipart.addBodyPart(messageBodyPart);
        }
        
    
        
    
        // Associate multi-part with message
        message.setContent(multipart);
    
        // Send message
        Transport.send(message);
      }
    }
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.