import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;
import lotus.domino.View;

/**
* @作者:wnight88
* @功能:通过用户名和密码直接连接邮件服务器代理
* @时间:2009-06-01
*/


public class LinkMail extends AgentBase
{
   public void NotesMain()
  {
     this.linkStart();
  }

   public void linkStart()
  {

     try
    {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      Document thisDoc = agentContext.getDocumentContext();
      Database thisDB = agentContext.getCurrentDatabase();

       // Database db = session.getDatabase(thisDB.getServer(), "go2mail");
      View view = thisDB.getView( "viewset");

      Document doc = view.getFirstDocument();
       while (doc != null)
      {
        System.out.println(doc.getItemValueString( "LoginName"));
        System.out.println(thisDoc.getItemValueString( "LoginName"));
         if (doc.getItemValueString( "LoginName").equals(
            thisDoc.getItemValueString( "LoginName")))
        {            
          thisDoc.replaceItemValue( "username", doc
              .getItemValue( "username"));
          thisDoc.replaceItemValue( "password", doc
              .getItemValue( "password"));
          thisDoc.replaceItemValue( "mailName",
               "10.139.3.3/names.nsf?Login&Username="
                  + doc.getItemValueString( "username")
                  + "&Password="
                  + doc.getItemValueString( "password"));
           break;
        }
        doc = view.getNextDocument(doc);
      }
       // (Your code goes here)

    }
     catch (Exception e)
    {
      e.printStackTrace();
    }
  }
    
   public static void main(String[] args)
  {
    System.out.println( "helloword!");
  }
}