0

I am using Alfresco 4.2c community edition . My requirement is to send a mail from user configured in James server so that the attachment i send to a mail id of a particular folder is uploaded into the folder . I have written the following code

public void sendAttachment(EmailVO emailVO) 
{
    try {

        String host = "01HW342035";
        String from = "alfresco@example.com";
        String to = "inbox@example.com";
        String user = "alfresco";
        String password = "alfresco";

        // Get system properties
        Properties properties = System.getProperties();

        // Setup mail server
        properties.setProperty("mail.smtp.host", host);

        // Get the default Session object.
        Session session = Session.getDefaultInstance(properties);

        // Define message
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO,
        new InternetAddress(to));
        message.setSubject("JavaMail Attachment");

        // Create the message part 
        BodyPart messageBodyPart = new MimeBodyPart();

        // Fill the message
        messageBodyPart.setText("hi");

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);

        // Part two is attachment
        messageBodyPart = new MimeBodyPart();
        String filename = "C:\\Users\\594952\\Desktop\\Links.txt";
        DataSource source = new FileDataSource(filename);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(filename);
        multipart.addBodyPart(messageBodyPart);

        // Put parts in message
        message.setContent(multipart);

        // Send the message
        Transport.send(message);
        System.out.println("Msg Send ....") ;
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

The code works fine and no exception occurs . I have configured james server and alfresco properties as per https://wiki.alfresco.com/wiki/Configuring_Email_With_Apache_James

I have given an alias as inbox to a folder in alfresco.The attachment i sent from the java code does not get uploaded into the repository. Kindly suggest the changes i should make to make this work correctly.

user2361591
  • 153
  • 1
  • 14

0 Answers0