javaemaillotus-noteslotus-dominointerop-domino

Not able to See Encyrpted Sent Mail via Java Program through Domino Sever


I am sending email through Domino Server by writing java mail sender program. Previously I was using notes dll but now I have switched to iiop. Since then I am not able to see the content of my sent Encrypted mail. The recepients can read the mail very well its just me. But I should be able to see my sent Encrypted mail.

When I send email via Lotus Notes client then it works. Did I forget to set anything in code or what?

Code used is below:

 public boolean sendMail(boolean schedule, String subject, String body, List<String> recipients, boolean doEncryt, boolean html, List<Binary> binaries, List<String> cc, List<String> bcc, List<String> replyTo)
    {

        String errorTxt = "";

        boolean diiop = true;
        try 
        { 
            Session session = null;
            // if (diiop)
            try {
                session = NotesFactory.createSession(NOTESMAILSERVER,"SOMEID",NOTESIDPW);
                diiop = true;
            }
            // else
            catch (Exception exc){
                NotesThread.sinitThread();
                session = NotesFactory.createSession();
                Registration lRegistration = session.createRegistration();
                lRegistration.switchToID(ResourceHelper.findResource(NOTESIDPATH).getFile().getAbsolutePath(), NOTESIDPW);
                diiop = false;
            }


            DbDirectory dir = session.getDbDirectory(NOTESMAILSERVER);
            Database    lDb = dir.openMailDatabase();

            session.setConvertMime(true);
            session.setConvertMIME(true);
            Document lDoc = lDb.createDocument();

            lDoc.replaceItemValue("Form"    ,"Memo");

            //set receip email addresses
            fillAdressItem(lDoc, recipients, "SendTo");
            fillAdressItem(lDoc, cc, "CopyTo");
            fillAdressItem(lDoc, bcc, "BlindCopyTo");

            //set subject
            lDoc.replaceItemValue("Subject" , subject);

            //set sender
            lDoc.replaceItemValue("From", this.FROM);
            lDoc.replaceItemValue("Principal", this.FROM);

            //prepare body text
            prepareRichTextBody(body, html, session, lDoc);

            //handle attachments
            RichTextItem lAttachmentItem = lDoc.createRichTextItem("attachments");

            if(binaries != null)
            {
                for(Binary binary : binaries)
                {

                    File tempFile = new File(getTempFolder(),binary.getName());
                    IOUtils.copyLarge(binary.getDataInputStream(), new FileOutputStream(tempFile));

                    lAttachmentItem.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", tempFile.getPath(), tempFile.getName());

                    tempFile.delete();
                }
            }

            //save if aSaveOnSend is true
            lDoc.setSaveMessageOnSend(true);

            //encrypt document if requested            
            if(doEncryt)
            {
                lDoc.setEncryptOnSend(true);
                lDoc.encrypt();
            }

            //send mail
            lDoc.send();

            return(true);
        } 
        catch(Throwable lE) 
        {

        }
        finally
        {
            if (!diiop) NotesThread.stermThread();
        }

    }

Kindly let me know what I am missing.

Thanks


Solution

  • You are calling both lDoc.setEncryptOnSend(true) and lDoc.encrypt(). The encrypt() method is normally used with setEncryptionKeys() to do secret key encryption. Email uses public key encryption.

    The help for the encrypt() method states

    Since mail encryption works differently, don't use this method if you want to mail an encrypted document. Instead, set the EncryptOnSend property to True, and use the Send method.

    Try getting rid of the call to lDoc.encrypt(). My guess is that by calling it, you're changing something in the internal state of the document (maybe creating an empty SecretEncryptionKeys item) that is messing things up while saving your copy of the Sent message.