Package javax.mail.internet

Examples of javax.mail.internet.AddressException


        final List sourcesList = new ArrayList();

        final MimeMessage message = new MimeMessage(this.session);

        if (this.from == null) {
            throw new AddressException("No from address");
        } else {
            try {
                message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException("Invalid from address: " + this.from + ": " +
                                           e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                message.setRecipients(RecipientType.TO,
                                      InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException("Invalid to address: " + this.to + ": " +
                                           e.getMessage());
            }
        }

        if (this.replyTo != null) {
            try {
                message.setReplyTo(InternetAddress.parse(this.replyTo));
            } catch (AddressException e) {
                throw new AddressException("Invalid replyTo address: " + this.replyTo + ": " +
                                           e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                message.setRecipients(RecipientType.CC,
                                      InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException("Invalid cc address: " + this.cc + ": " +
                                           e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                message.setRecipients(RecipientType.BCC,
                                      InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException("Invalid bcc address: " + this.bcc + ": " +
                                           e.getMessage());
            }
        }

        if (this.subject != null) {
            message.setSubject(this.subject);
        }

        message.setSentDate(new Date());

        Attachment a = null;
        try {
            if (this.attachments.isEmpty()) {
                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    message.setDataHandler(new DataHandler(ds));

                } else if (this.body != null) {
                    if (this.charset != null) {
                        message.setText(this.body, this.charset);
                    } else {
                        message.setText(this.body);
                    }
                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = new MimeBodyPart();
                multipart.addBodyPart(bodypart);
                message.setContent(multipart);

                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());

                } else if (this.body != null) {
                    bodypart.setText(this.body);
                }

                for (Iterator i = this.attachments.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds =
                                new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds =
                                new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }

            message.saveChanges();
            Transport.send(message);
        } catch (MessagingException me) {
            throw new MessagingException(me.getMessage());
        } catch (MalformedURLException e) {
            throw new AddressException("Malformed attachment URL: " +
                                       a.getObject() + " error " + e.getMessage());
        } catch (IOException e) {
            throw new AddressException("IOException accessing attachment URL: " +
                                       a.getObject() + " error " + e.getMessage());
        } finally {
            if (sourcesList != null) {
                for (Iterator j = sourcesList.iterator(); j.hasNext();) {
                    resolver.release((Source) j.next());
View Full Code Here


        final List sourcesList = new ArrayList();

        final MimeMessage message = new MimeMessage(this.session);

        if (this.from == null) {
            throw new AddressException("no from address");
        } else {
            try {
                message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid from address: " + this.from + ": " + e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                message.setRecipients(RecipientType.TO,
                                      InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid to address: " + this.to + ": " + e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                message.setRecipients(RecipientType.CC,
                                      InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid cc address: " + this.cc + ": " + e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                message.setRecipients(RecipientType.BCC,
                                      InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid bcc address: " + this.bcc + ": " + e.getMessage());
            }
        }

        if (this.subject != null) {
            message.setSubject(this.subject);
        }

        message.setSentDate(new Date());

        Attachment a = null;
        try {
            if (this.attachments.isEmpty()) {
                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    message.setDataHandler(new DataHandler(ds));

                } else if (this.body != null) {
                    if (this.charset != null) {
                        message.setText(this.body, this.charset);
                    } else {
                        message.setText(this.body);
                    }
                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = new MimeBodyPart();
                multipart.addBodyPart(bodypart);
                message.setContent(multipart);

                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());

                } else if (this.body != null) {
                    bodypart.setText(this.body);
                }

                for (Iterator i = this.attachments.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds =
                                new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds =
                                new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }

            message.saveChanges();
            Transport.send(message);
        } catch (MessagingException me) {
            throw new MessagingException(me.getMessage());
        } catch (MalformedURLException e) {
            throw new AddressException("Malformed attachment URL: " +
                                       a.getObject() + " error " + e.getMessage());
        } catch (IOException e) {
            throw new AddressException("IOException accessing attachment URL: " +
                                       a.getObject() + " error " + e.getMessage());
        } finally {
            if (sourcesList != null) {
                for (Iterator j = sourcesList.iterator(); j.hasNext();) {
                    resolver.release((Source) j.next());
View Full Code Here

    throws AddressException, MessagingException {

        final MimeMessage message = new MimeMessage(this.session);

        if (this.from == null) {
            throw new AddressException("No from address");
        } else {
            try {
                message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException("Invalid from address: " + this.from + ": " +
                                           e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                message.setRecipients(RecipientType.TO,
                                      InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException("Invalid to address: " + this.to + ": " +
                                           e.getMessage());
            }
        }

        if (this.replyTo != null) {
            try {
                message.setReplyTo(InternetAddress.parse(this.replyTo));
            } catch (AddressException e) {
                throw new AddressException("Invalid replyTo address: " + this.replyTo + ": " +
                                           e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                message.setRecipients(RecipientType.CC,
                                      InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException("Invalid cc address: " + this.cc + ": " +
                                           e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                message.setRecipients(RecipientType.BCC,
                                      InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException("Invalid bcc address: " + this.bcc + ": " +
                                           e.getMessage());
            }
        }

        if (this.subject != null) {
View Full Code Here

  }

  private InternetAddress parseAddress(String address) throws MessagingException {
    InternetAddress[] parsed = InternetAddress.parse(address);
    if (parsed.length != 1) {
      throw new AddressException("Illegal address", address);
    }
    InternetAddress raw = parsed[0];
    try {
      return (getEncoding() != null ?
          new InternetAddress(raw.getAddress(), raw.getPersonal(), getEncoding()) : raw);
View Full Code Here

     */
    public void send(SourceResolver resolver) throws AddressException, MessagingException {
        List sourcesList = new ArrayList();

        if (this.from == null) {
            throw new AddressException("no from address");
        } else {
            try {
                this.message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException("invalid from address: " + this.from + ": " + e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                this.message.setRecipients(RecipientType.TO, InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException("invalid to address: " + this.to + ": " + e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                this.message.setRecipients(RecipientType.CC, InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException("invalid cc address: " + this.cc + ": " + e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                this.message.setRecipients(RecipientType.BCC, InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException("invalid bcc address: " + this.bcc + ": " + e.getMessage());
            }
        }

        if (this.subject != null) {
            this.message.setSubject(this.subject);
        }

        message.setSentDate(new Date());

        Attachment a = null;
        try {

            if (this.attachmentList.isEmpty()) {
                if (this.body != null) {
                    if (this.charset != null) {
                        this.message.setText(this.body, this.charset);
                    } else {
                        this.message.setText(this.body);
                    }
                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = null;
                if (this.body != null) {
                    bodypart = new MimeBodyPart();
                    bodypart.setText(this.body);
                    multipart.addBodyPart(bodypart);
                }
                this.message.setContent(multipart);

                for (Iterator i = this.attachmentList.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds = new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds = new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }

            Transport.send(this.message);
        } catch (MessagingException me) {
            throw new MessagingException(me.getMessage());
        } catch (MalformedURLException e) {
            throw new AddressException("Malformed attachment URL: " + a.getObject() + " error " + e.getMessage());
        } catch (IOException e) {
            throw new AddressException(
                "IOException accessing attachment URL: " + a.getObject() + " error " + e.getMessage());
        } finally {
            if (sourcesList != null) {
                for (Iterator j = sourcesList.iterator(); j.hasNext();) {
                    resolver.release((Source) j.next());
View Full Code Here

        try {
            InternetAddress address = new InternetAddress(input, true);
            result = address.getAddress();
            if (!result.contains("@")) {
                result = null;
                throw new AddressException();
            }
        }
        catch (AddressException ae) {
            errors.add( new ScopedLocalizableError("converter.email", "invalidEmail") );
        }
View Full Code Here

            String mimeCharset = MimeUtility.mimeCharset(getJavaCharset(javaCharset));

            for (InternetAddress addr : addrs) {
                // JavaMail 1.4.2以上,在parse时就会报empty address错误。在此处判断,使较低版的javamail行为一致。
                if (isEmpty(addr.getAddress())) {
                    throw new AddressException("Empty address");
                }

                addr.setPersonal(trimToNull(addr.getPersonal()), mimeCharset);
            }
        }
View Full Code Here

            String mimeCharset = MimeUtility.mimeCharset(getJavaCharset(javaCharset));

            for (InternetAddress addr : addrs) {
                // JavaMail 1.4.2���ϣ���parseʱ�ͻᱨempty address�����ڴ˴��жϣ�ʹ�ϵͰ��javamail��Ϊһ�¡�
                if (isEmpty(addr.getAddress())) {
                    throw new AddressException("Empty address");
                }

                addr.setPersonal(trimToNull(addr.getPersonal()), mimeCharset);
            }
        }
View Full Code Here

     */
    public void send(SourceResolver resolver) throws AddressException, MessagingException {
        List sourcesList = new ArrayList();

        if (this.from == null) {
            throw new AddressException("no from address");
        } else {
            try {
                this.message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException("invalid from address: " + this.from + ": " + e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                this.message.setRecipients(RecipientType.TO, InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException("invalid to address: " + this.to + ": " + e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                this.message.setRecipients(RecipientType.CC, InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException("invalid cc address: " + this.cc + ": " + e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                this.message.setRecipients(RecipientType.BCC, InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException("invalid bcc address: " + this.bcc + ": " + e.getMessage());
            }
        }

        if (this.subject != null) {
            this.message.setSubject(this.subject);
        }

        message.setSentDate(new Date());

        Attachment a = null;
        try {

            if (this.attachmentList.isEmpty()) {
                if (this.body != null) {
                    if (this.charset != null) {
                        this.message.setText(this.body, this.charset);
                    } else {
                        this.message.setText(this.body);
                    }
                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = null;
                if (this.body != null) {
                    bodypart = new MimeBodyPart();
                    bodypart.setText(this.body);
                    multipart.addBodyPart(bodypart);
                }
                this.message.setContent(multipart);

                for (Iterator i = this.attachmentList.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds = new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds = new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }

            Transport.send(this.message);
        } catch (MessagingException me) {
            throw new MessagingException(me.getMessage());
        } catch (MalformedURLException e) {
            throw new AddressException("Malformed attachment URL: " + a.getObject() + " error " + e.getMessage());
        } catch (IOException e) {
            throw new AddressException(
                "IOException accessing attachment URL: " + a.getObject() + " error " + e.getMessage());
        } finally {
            if (sourcesList != null) {
                for (Iterator j = sourcesList.iterator(); j.hasNext();) {
                    resolver.release((Source) j.next());
View Full Code Here

   */
  public Email(String emailAddress) throws AddressException {
    if (validate(emailAddress)) {
      this.emailAddress = emailAddress;
    } else {
      throw new AddressException(emailAddress
          + " is not a valid email address.");
    }
  }
View Full Code Here

TOP

Related Classes of javax.mail.internet.AddressException

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.