eml file generation

0
Hi, Im using the below java code to generate the .eml file. https://stackoverflow.com/questions/157195/create-a-eml-email-file-in-java I can able to generate the .eml file successfully. But if I pass the content(which is html), the generated file is not in proper way.    Thanks in advance
asked
2 answers
0

Can you share your Java Action code? Are you setting the content-type as text/html in your code?
 

answered
0

Hi Robert,

Please find below the java code which is used to generate eml file
try {
        
            Message message = new MimeMessage(Session.getInstance(System.getProperties()));
            message.setFrom(new InternetAddress(From));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(To));
            message.setSubject(Subject);
            // create the message part 
            MimeBodyPart content = new MimeBodyPart();
            content.setHeader("Content-Type", "text/html; charset=UTF-8"); 
          
          
            // fill message
            content.setText(Body);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(content);
            // add attachments
            /*
             * for(File file : attachments) { MimeBodyPart attachment = new MimeBodyPart();
             * DataSource source = new FileDataSource(file); attachment.setDataHandler(new
             * DataHandler(source)); attachment.setFileName(file.getName());
             * multipart.addBodyPart(attachment); }
             */
            // integration
            message.setContent(multipart,"text/html; charset=UTF-8");
           
            // store file

           
           String temppath=Core.getConfiguration().getTempPath().getAbsolutePath();
           Logger.getLogger("EmailFileConvertion").info("TempPath::"+temppath);
           String FilePath=temppath+"/sampleEmail.eml";
           Logger.getLogger("EmailFileConvertion").info("TempFullPath::"+FilePath);
                   File tempFile1 = new File(FilePath);
                FileOutputStream fos = new FileOutputStream(tempFile1);
                      message.writeTo(fos);
                      FileInputStream fis = new FileInputStream(tempFile1);
                      Core.storeFileDocumentContent(getContext(), FileDocument.getMendixObject(), 
                                FilePath, fis);

        } catch (MessagingException ex) {
            Logger.getLogger("EmailFileConvertion").info(ex.toString());
            return false;
            //Logger.getLogger(Mailkit.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException io) {
            Logger.getLogger("EmailFileConvertion").info(io.toString());
            return false;
            //Logger.getLogger(Mailkit.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;

answered