Search code examples
javaemaillotus-noteslotus-domino

how to bypass lotus notes password log in - JAVA code


My code works great so far, except for one part which I need to bypass somehow because this is going to be an autosys job. That one part is logging in to lotus notes (when I'm logged in and the app is still running); every time my script runs it requires the user to input his password. I've tried code to log in to my account but it still didn't work for me, so I was wondering what am I missing? Any help would be greatly appreciated! My code is below. It is very close to being finished. The popup is the only issue I have; the code below is compilable and runs just fine so far.

import java.io.IOException;

import java.util.*;

import javax.mail.*;
import javax.mail.Session;
import javax.mail.internet.*;
import javax.swing.JOptionPane;
import javax.activation.*;

import lotus.domino.*;
import lotus.notes.addins.util.DominoAddressBook;

public class SendEmail extends NotesThread {

    @SuppressWarnings("deprecation")
    public static void main(String [] args) throws AddressException, MessagingException {
        // runs the program, mainly runNotes()
        SendEmail e = new SendEmail();
        e.start();  
        //e.sendMail();
    }

    public void runNotes() {
        try {           
            // TODO: pop's up dialog box for user password to be input if password is in line 32 else its line 59
            // might be because I'm creating a new session each time the program is run?
            // this lets you retype the password as many times as you want until you got it correct (no password in argument, line 32)
            lotus.domino.Session s = NotesFactory.createSessionWithFullAccess();

            // configures so the password entered in the dialog box matches the password here (security check user)
            // lotus.domino.Session s = NotesFactory.createSession((String)null, "userID", "pass!");    

            String p = s.getPlatform();
            System.out.println("Platform: " + p);

            System.out.println("Username: " + s.getUserName());
            System.out.println("Server name: " + s.getServerName());

            // self explantory, set's up the email with the message, attachment, etc
            Database db = s.getDatabase(null, "C:\\Program Files (x86)\\IBM\\Lotus\\Notes\\Data\\names.nsf");
            Document doc = db.createDocument();

            doc.setSaveMessageOnSend(true);
            RichTextItem attachedFile = doc.createRichTextItem("Attachment");
            attachedFile.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "G-Man", "C:\\Users\\F400318\\Desktop\\testDB2.xlsx", "testDB");

            StringBuilder body = new StringBuilder();
            body.append("This email is a test!");

            doc.appendItemValue("\n\n");
            doc.appendItemValue("Body", body.toString());
            doc.appendItemValue("Subject", "Test E-Mail");
            doc.appendItemValue("Sent", "[email protected]");

            doc.send("[email protected]");

            System.out.println("Check email... it should have been sent");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Solution

  • Where is your code running? On a Domino server, from a Notes client, or outside of Notes/Domino entirely?

    The createSessionWithFullAccess() method assumes the code is running on the server and it will prompt for the password when needed unless you pass the password as an argument createSessionWithFullAccess("password").

    http://www-12.lotus.com/ldd/doc/domino_notes/rnext/help6_designer.nsf/b3266a3c17f9bb7085256b870069c0a9/5a8f8afb89d617f785256c54004d9eb4?OpenDocument

    * Edit *

    From the looks of your code, you're trying to create a Swing application with JOptionPane, so using createSessionWithFullAccess() isn't necessary from the Notes client. You could just use NotesFactory.createSession() and it will use the users's Notes ID for credentials. Another option you could consider is if you're calling your code from a Notes agent, then you could pass the Session created by the agent to your code instead of creating a new one.