Package javax.mail

Examples of javax.mail.MessagingException


    if (port < 0)
      port = 25;

    // XXX: pooling
    if (_socket != null)
      throw new MessagingException(L.l("Attempted to connect to open connection."));

    try {
      _socket = new Socket(host, port);
      _socket.setSoTimeout(10000);
      SocketStream s = new SocketStream(_socket);
   
      _os = new WriteStream(s);
      _is = new ReadStream(s, _os);

      String line = _is.readLine();
     
      log.fine("smtp connection to " + host + ":" + port + " succeeded");
      log.fine("smtp: " + line);

      _os.print("EHLO " + CauchoSystem.getLocalHost() + "\r\n");
      _os.flush();

      readResponse();

      setConnected(true);
    } catch (IOException e) {
      log.fine("smtp connection to " + host + ":" + port + " failed: " + e);

      log.log(Level.FINER, e.toString(), e);
     
      throw new MessagingException("smtp connection to " + host + ":" + port + " failed.\n" + e);
    }

    return true;
  }
View Full Code Here


   */
  public void sendMessage(Message msg, Address []addresses)
    throws MessagingException
  {
    if (! isConnected())
      throw new MessagingException("Transport does not have an active connection.");

    if (! (msg instanceof MimeMessage))
      throw new MessagingException("message must be a MimeMessage at '"
                                   + msg.getClass().getName() + "'");

    MimeMessage mimeMsg = (MimeMessage) msg;

    try {
      // XXX: EHLO to resync? or RSET?
      // XXX: FROM

      String []fromList = mimeMsg.getHeader("From");
      String from;
     
      if (fromList == null || fromList.length < 1) {
        // XXX: possible should have a default
        throw new MessagingException("message should have a sender");
      }
      else
        from = fromList[0];
     
      _os.print("MAIL FROM:<" + from + ">\r\n");
      _os.flush();

      if (log.isLoggable(Level.FINER))
        log.finer("mail from:<" + from + ">");

      readResponse();

      for (int i = 0; i < addresses.length; i++) {
        InternetAddress addr = (InternetAddress) addresses[i];

        if (log.isLoggable(Level.FINER))
          log.finer("mail to:<" + addr.getAddress() + ">");

        _os.print("RCPT TO:<" + addr.getAddress() + ">\r\n");
        _os.flush();

        readResponse();
      }

      _os.print("DATA\r\n");
      _os.flush();

      String line = _is.readLine();
      if (! line.startsWith("354 "))
        throw new MessagingException("Data not accepted: " + line);

      mimeMsg.writeTo(new DataFilter(_os));

      _os.print("\r\n.\r\n");
      _os.flush();
    } catch (IOException e) {
      log.log(Level.FINER, e.toString(), e);

      throw new MessagingException(e.toString());
    }
  }
View Full Code Here

    throws IOException, MessagingException
  {
    while (true) {
      String line = _is.readLine();
      if (line.length() < 4)
        throw new MessagingException(line);

      int status = 0;
      for (int i = 0; i < 3; i++) {
        char ch;

        if ('0' <= (ch = line.charAt(i))  && ch <= '9')
          status = 10 * status + ch - '0';
      }

      if ((status / 100) % 10 != 2)
        throw new MessagingException(line);

      if (line.charAt(3) != '-')
        return status;
    }
  }
View Full Code Here

            }
            message.setFrom(new InternetAddress(email, name));
        }
        catch (Exception e)
        {
            throw new MessagingException("cannot set from", e);
        }
        return this;
    }
View Full Code Here

            }
            toList.addElement(new InternetAddress(email, name));
        }
        catch (Exception e)
        {
            throw new MessagingException("cannot add to", e);
        }
        return this;
    }
View Full Code Here

            }
            ccList.addElement(new InternetAddress(email, name));
        }
        catch (Exception e)
        {
            throw new MessagingException("cannot add cc", e);
        }

        return this;
    }
View Full Code Here

            }
            bccList.addElement(new InternetAddress(email, name));
        }
        catch (Exception e)
        {
            throw new MessagingException("cannot add bcc", e);
        }

        return this;
    }
View Full Code Here

            }
            replyList.addElement(new InternetAddress(email, name));
        }
        catch (Exception e)
        {
            throw new MessagingException("cannot add replyTo", e);
        }
        return this;
    }
View Full Code Here

                String file = attachment.getPath();
                url = new URL("file", fileServer, file);
            }
            catch (Exception e)
            {
                throw new MessagingException("Cannot find file", e);
            }
        }

        return attach(url, attachment.getName(),
                attachment.getDescription(),
View Full Code Here

        /*
         * don't bother me w/ null messages or no addreses
         */

        if (message == null ) {
            throw new MessagingException("Null message");
        }

        if (addresses == null || addresses.length == 0) {
            throw new MessagingException("Null or empty address array");
        }


        SendStatus[] stat = new SendStatus[addresses.length];

        try {

            /*
             * create socket and connect to server.
             */

            Socket s = getConnectedSocket();

            /*
             *  receive welcoming message
             */
            if (!getWelcome(s)) {
                throw new MessagingException("Error in getting welcome msg");
            }

            /*
             * say hello
             */
            if (!sendHelo(s)) {
                throw new MessagingException("Error in saying HELO to server");
            }

            /*
             * send sender
             */
            if (!sendMailFrom(s, message.getFrom())) {
                throw new MessagingException("Error in setting the MAIL FROM");
            }

            /*
             * send recipients.  Only send if not null or "", and just ignore
             * (but log) any errors
             */

            for (int i=0; i < addresses.length; i++) {
                String to = addresses[i].toString();

                int status = SendStatus.SUCCESS;

                if (to != null && !"".equals(to)) {
                    if (!sendRcptTo(s, to)) {

                        // this means it didn't like our recipient.  I say we keep
                        // going

                        if (this.session.getDebug()) {
                            this.session.getDebugOut().println("ERROR setting recipient " + to);
                        }

                        status = SendStatus.FAIL;
                    }
                }
                else {
                    status = SendStatus.FAIL;
                }

                stat[i] = new SendStatus(status, to);
            }

            /*
             * send data
             */
            if (!sendData(s, message)) {
                throw new MessagingException("Error sending data");
            }

            /*
             * say goodbye
             */

            sendQuit(s);

            try {
                s.close();
            }
            catch (IOException e) {
                //
                // TODO - should we just eat this?  We have delivered the msg...
                //
                e.printStackTrace();
            }
        }
        catch (SMTPTransportException e) {
            throw new MessagingException("error", e);
        }
        catch (MalformedSMTPReplyException e) {
            throw new MessagingException("error", e);
        }

        return stat;
    }
View Full Code Here

TOP

Related Classes of javax.mail.MessagingException

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.