Package javax.mail

Examples of javax.mail.URLName


    baseMsg.setSubject("Test Big attached file message");
    baseMsg.setContent(multipart);
    baseMsg.saveChanges();

    log.debug("Send started");
    Transport t = new SMTPTransport(session, new URLName("smtp://localhost:"+SMTP_PORT));
    long started = System.currentTimeMillis();
    t.connect();
    t.sendMessage(baseMsg, new Address[] {new InternetAddress(
        "success@subethamail.org")});
    t.close();
View Full Code Here


  private void parseIMAPFolder(String folderUrl) throws RegainException {

    mLog.debug("Determine IMAP subfolder for: " + folderUrl);
    Session session = Session.getInstance(new Properties());

    URLName originURLName = new URLName(
      CrawlerToolkit.replaceAuthenticationValuesInURL(folderUrl,
      CrawlerToolkit.findAuthenticationValuesForURL(folderUrl, accountPasswordStore)));
    // Replace all %20 with whitespace in folder pathes
    String folder = "";
    if (originURLName.getFile() != null) {
      folder = originURLName.getFile().replaceAll("%20", " ");
    }
    URLName urlName = new URLName(originURLName.getProtocol(), originURLName.getHost(),
      originURLName.getPort(), folder, originURLName.getUsername(), originURLName.getPassword());

    Map<String, Integer> folderList = new Hashtable<String, Integer>();

    try {
      IMAPSSLStore imapStore = new IMAPSSLStore(session, urlName);

      imapStore.connect();
      IMAPFolder startFolder;

      if (urlName.getFile() == null) {
        // There is no folder given
        startFolder = (IMAPFolder) imapStore.getDefaultFolder();
      } else {
        startFolder = (IMAPFolder) imapStore.getFolder(urlName.getFile());
      }

      // Find messages (if folder exist and could be openend)
      if (startFolder.exists()) {
        try {
View Full Code Here

    if (!((DBStore)getStore()).isConnected())
      throw new StoreClosedException(getStore(), "Store is not connected");

    com.knowgate.acl.ACLUser oUsr = ((DBStore)getStore()).getUser();
    return new URLName("jdbc://", "localhost", -1, oCatg.getString(DB.gu_category), oUsr.getString(DB.gu_user), oUsr.getString(DB.tx_pwd));
  }
View Full Code Here

        // which is used for composing the path to outbox mbox file containing
        // source of message to be sent
        sProfile = getParameter("profile");
        sMBoxDir = DBStore.MBoxDirectory(sProfile,iDomainId,sWrkA);

        oStor = new DBStore(oHndlr.getSession(), new URLName("jdbc://", sProfile, -1, sMBoxDir, oUser.getString(DB.gu_user), oUser.getStringNull(DB.tx_pwd,"")));
        oStor.connect(sProfile, oUser.getString(DB.gu_user), oUser.getStringNull(DB.tx_pwd,""));
        oOutBox = (DBFolder) oStor.getFolder("outbox");
        oOutBox.open(Folder.READ_WRITE);
        String sMsgId = getParameter("message");
View Full Code Here

          if (oHndlr==null) {
            throw new MessagingException("Session lost. SessionHandler is null");
          } else if (oHndlr.getSession()==null) {
            throw new MessagingException("Session lost. SessionHandler.getSession() is null");
          } else {
            oStor = new DBStore(oHndlr.getSession(), new URLName("jdbc://", sProfile, -1, sMBoxDir, oUser.getString(DB.gu_user), oUser.getStringNull(DB.tx_pwd,"")));
            oStor.connect(sProfile, oUser.getString(DB.gu_user), oUser.getStringNull(DB.tx_pwd,""));
            oSent = (DBFolder) oStor.getFolder("sent");
            oSent.open(Folder.READ_WRITE);
            oSent.moveMessage(oDraft);
          oSent.close(false);
View Full Code Here

    /**
     * Delegates the method to the new URLName class
     */
    public Folder getFolder(String name) throws MessagingException {
        return getFolder(new URLName(name));
    }
View Full Code Here

       
        log.info("Connecting to store/floder...");
        final Session session = Session.getInstance(options.genProperties());
        session.setDebug(options.isDebug());
 
        final URLName imapUrlName = options.genImapUrlName();
        store = (IMAPStore) session.getStore(imapUrlName);
 
        final InternalConnectionListener connectionListener = new InternalConnectionListener();
        //store.addConnectionListener(connectionListener);
        store.connect(imapUrlName.getHost(), imapUrlName.getPort(), imapUrlName.getUsername(), imapUrlName.getPassword());
        mainFolder = (IMAPFolder) store.getFolder(options.getImapFolder());
        mainFolder.addConnectionListener(connectionListener);
        mainFolder.open(Folder.READ_ONLY);
        mainFolder.addMessageCountListener(new MessageCountAdapter() {
 
          @Override
          public void messagesAdded(MessageCountEvent event) {
            log.debug("Incoming messages...");
            try {
              if (listeners.isEmpty()) {
                log.warn("No listeners available for executing remote commands");
                return;
              }
              final Message[] msgs = event.getMessages();
              IMAPMessage msg;
              for (final Message rmsg : msgs) {
                if (!(rmsg instanceof IMAPMessage)) {
                  log.info(String.format("Expected %1$s, but received %2$s subject: %3$s",
                      IMAPMessage.class.getSimpleName(), rmsg.getClass().getSimpleName(), rmsg.getSubject()));
                  continue;
                }
                msg = (IMAPMessage) rmsg;
                final Address[] froms = msg.getFrom();
                if (hasCommandPermission(froms)) {
                  final StringBuffer errorMessages = new StringBuffer();
                  final List<Command> commands = getValidCommands(msg, errorMessages);
                  final Set<String> destinations = getValidCommandDestinations(msg, errorMessages);
                  if (errorMessages.length() > 0) {
                    if (log.isInfoEnabled()) {
                      log.info(String.format("Invalid command(s) received from: %1$s", Arrays.toString(froms)));
                    }
                    sendReply(msg, errorMessages.toString());
                    return;
                  }
                  if (log.isInfoEnabled()) {
                    log.info(String.format("Received raw commands: %1$s from: %2$s",
                        Arrays.toString(commands.toArray()), Arrays.toString(froms)));
                  }
                  final Thread newThread = new Thread(getThreadName(msg.getMessageID())) {
                    @Override
                    public void run() {
                      final EmailEvent event = new EmailEvent(EmailEvent.Type.EXECUTE_COMMAND, commands,
                          froms, destinations);
                      for (final IEmailListener listener : listeners) {
                        listener.handle(event);
                      }
                    }
                  };
                  newThread.start();
                } else if (log.isInfoEnabled()) {
                  log.info(String.format("Received an email message from %1$s, but they do not have permission to execute commands",
                      Arrays.toString(froms)));
                }
              }
            } catch (Exception e) {
              log.error("Error when processing incoming message", e);
            }
          }
        });
        log.info("Connected to " + imapUrlName.getHost() + " waiting for messages...");
        // when idle (blocking) gets interrupted (by host, sending an email, getting message content, etc.)
        // try to reinstate the idle process, if that fails (usually due to a closed folder) try to reconnect
        while (runIt) {
          mainFolder.idle();
          if (runIt) {
View Full Code Here

   * @param msg
   *            the message to send
   */
  protected void send(final Session session, final MimeMessage msg) {
    try {
      final URLName smtpUrlName = options.genSmtpUrlName();
      log.debug("Opening transport to: " + smtpUrlName);
      final Transport transport = session.getTransport(smtpUrlName);
      transport.connect(smtpUrlName.getHost(), smtpUrlName.getPort(),
          smtpUrlName.getUsername(), smtpUrlName.getPassword());
      transport.sendMessage(msg, msg.getAllRecipients());
      transport.close();
      log.info("Message sent");
    } catch (Exception e) {
      log.error("Unable to send message", e);
View Full Code Here

    /**
     * @return the {@link URLName} for outgoing SMTP messages
     */
    private final URLName genSmtpUrlName() {
      return new URLName(genSmtpProtocol(), getSmtpHost(), getSmtpPort(),
          null, getSmtpUsername(), getSmtpPassword());
    }
View Full Code Here

    /**
     * @return the {@link URLName} for incoming IMAP messages
     */
    private final URLName genImapUrlName() {
      return new URLName(genImapProtocol(), getImapHost(), getImapPort(),
          null, getImapUsername(), getImapPassword());
    }
View Full Code Here

TOP

Related Classes of javax.mail.URLName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.