Example usage for javax.mail.internet AddressException printStackTrace

List of usage examples for javax.mail.internet AddressException printStackTrace

Introduction

In this page you can find the example usage for javax.mail.internet AddressException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:transport.java

public static void main(String[] args) {
    Properties props = System.getProperties();
    // parse the arguments
    InternetAddress[] addrs = null;/*from w ww  . j  a  va2  s .  co m*/
    InternetAddress from;
    boolean debug = false;
    if (args.length != 4) {
        usage();
        return;
    } else {
        props.put("mail.smtp.host", args[2]);
        if (args[3].equals("true")) {
            debug = true;
        } else if (args[3].equals("false")) {
            debug = false;
        } else {
            usage();
            return;
        }

        // parse the destination addresses
        try {
            addrs = InternetAddress.parse(args[0], false);
            from = new InternetAddress(args[1]);
        } catch (AddressException aex) {
            System.out.println("Invalid Address");
            aex.printStackTrace();
            return;
        }
    }
    // create some properties and get a Session
    Session session = Session.getInstance(props, null);
    session.setDebug(debug);

    transport t = new transport();
    t.go(session, addrs, from);
}

From source file:transport.java

public static void main(String[] args) {
    Properties props = new Properties();
    // parse the arguments
    InternetAddress[] addrs = null;/*from   w ww  .  j a v a2 s.c  o m*/
    InternetAddress from;
    boolean debug = false;
    if (args.length != 4) {
        usage();
        return;
    } else {
        props.put("mail.smtp.host", args[2]);
        if (args[3].equals("true")) {
            debug = true;
        } else if (args[3].equals("false")) {
            debug = false;
        } else {
            usage();
            return;
        }

        // parse the destination addresses
        try {
            addrs = InternetAddress.parse(args[0], false);
            from = new InternetAddress(args[1]);
        } catch (AddressException aex) {
            System.out.println("Invalid Address");
            aex.printStackTrace();
            return;
        }
    }
    // create some properties and get a Session
    Session session = Session.getInstance(props, null);
    session.setDebug(debug);

    transport t = new transport();
    t.go(session, addrs, from);
}

From source file:ca.uqac.info.Job.Launcher.JobLauncher.java

/**
 * Send a email if the option is choosen by the user
 * @param Gmail the object who does the treatment
 * @param emailOpt contain the choice of the user for the email option
 * @param username the email used to send email
 * @param password the password needed to connect into the email account
 * @param recipient the email adress of the receiver
 * @param title the title of the email// w  w  w  .j av a  2s.  c  om
 * @param message the message of the email
 */
private static void sendEmail(GoogleMail Gmail, boolean emailOpt, String username, String password,
        String recipient, String title, String message) {
    // The option has been chosen by the user
    if (emailOpt == true) {
        //The request is done !
        try {
            Gmail.Send(username, password, recipient, title, message);
        } catch (AddressException e) {
            System.out.println("AddressException during the email Sending !");
            e.printStackTrace();
        } catch (MessagingException e) {
            System.out.println("MessagingException during the email Sending !");
            e.printStackTrace();
        }
    }
}

From source file:com.clueride.domain.account.principal.EmailPrincipal.java

public EmailPrincipal(String email) {
    try {/*from ww w  .  ja  v a  2  s . c  o  m*/
        emailAddress = new InternetAddress(email);
    } catch (AddressException e) {
        e.printStackTrace();
    }
}

From source file:pe.chalk.takoyaki.model.Member.java

public InternetAddress getInternetAddress() {
    try {/*from  w  ww  .  jav a  2s .  com*/
        return new InternetAddress(this.getUsername() + "@" + this.getHost());
    } catch (AddressException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:de.fzi.ALERT.actor.ActionActuator.MailService.java

public void sendEmail(Authenticator auth, String address, String subject, String content) {
    try {//w  ww .  j  a  va 2 s .c o m
        Properties props = new Properties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.port", port);
        props.put("mail.smtp.auth", true);
        props.put("mail.smtp.starttls.enable", "true");

        Session session = Session.getDefaultInstance(props, auth);
        // -- Create a new message --
        Message msg = new MimeMessage(session);

        // -- Set the FROM and TO fields --
        msg.setFrom(new InternetAddress(username));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(address, false));

        // -- Set the subject and body text --
        msg.setSubject(subject);
        msg.setText(content);

        // -- Set some other header information --
        msg.setHeader("X-Mailer", "LOTONtechEmail");
        msg.setSentDate(new Date());

        // -- Send the message --
        Transport.send(msg);

        System.out.println("An announce Mail has been send to " + address);
    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.gatherdata.alert.notify.mail.internal.MailtoUrl.java

/**
 * Gets the internet email addresses contained within the mailbox section.
 * //from   w  w w .  j  a  v  a  2  s . com
 * @return
 */
public List<InternetAddress> getMailboxAddresses() {
    List<InternetAddress> addies = new ArrayList<InternetAddress>();

    String mailbox = getMailbox();
    StringTokenizer mailboxTokens = new StringTokenizer(mailbox, ",");
    while (mailboxTokens.hasMoreTokens()) {
        try {
            addies.add(new InternetAddress(mailboxTokens.nextToken().trim()));
        } catch (AddressException e) {
            System.err.println("failed to parse all internet addresses from mailbox: " + mailbox);
            e.printStackTrace();
        }
    }
    return addies;
}

From source file:org.overlord.sramp.governance.services.NotificationResourceTest.java

@Test
public void testMail() {
    try {//  www. jav a 2s  . c om
        mailServer = SimpleSmtpServer.start(smtpPort);
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$
        properties.setProperty("mail.smtp.port", String.valueOf(smtpPort)); //$NON-NLS-1$
        Session mailSession = Session.getDefaultInstance(properties);
        MimeMessage m = new MimeMessage(mailSession);
        Address from = new InternetAddress("me@gmail.com"); //$NON-NLS-1$
        Address[] to = new InternetAddress[1];
        to[0] = new InternetAddress("dev@mailinator.com"); //$NON-NLS-1$
        m.setFrom(from);
        m.setRecipients(Message.RecipientType.TO, to);
        m.setSubject("test"); //$NON-NLS-1$
        m.setContent("test", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
        Transport.send(m);

        Assert.assertTrue(mailServer.getReceivedEmailSize() > 0);
        @SuppressWarnings("rawtypes")
        Iterator iter = mailServer.getReceivedEmail();
        while (iter.hasNext()) {
            SmtpMessage email = (SmtpMessage) iter.next();
            System.out.println(email.getBody());
            Assert.assertEquals("test", email.getBody()); //$NON-NLS-1$
        }

    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        mailServer.stop();
    }

}

From source file:com.hygenics.parser.Send.java

public void run() {

    try {/*from www  .  j av  a2  s .c o  m*/
        log.info("Creating Message");
        MimeMessage message = mailSender.createMimeMessage();

        MimeMessageHelper helper = new MimeMessageHelper(message, true);

        InternetAddress addr = new InternetAddress(fromEmails);

        helper.setFrom(addr);

        for (String email : emails) {
            helper.addTo(new InternetAddress(email));
        }

        helper.setSubject(subject);
        helper.setText(body);

        if (fpath != null) {
            log.info("Attaching File");
            File f = new File(fpath);

            if (f.exists()) {
                helper.addAttachment(fpath, f);
            }
        }

        log.info("Sending Email");
        mailSender.send(message);

    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.jevis.emaildatasource.EmailForTest.java

public void testMail() throws MessagingException {
    List<InputStream> answerList = new ArrayList<InputStream>();

    _userName = "artur.iablokov@envidatec.com";
    _password = "na733aya";
    _host = "imap.1und1.de";

    Properties props = new Properties();
    props.put("mail.debug", "true");
    props.put("mail.store.protocol", "imaps");
    _session = Session.getInstance(props);
    _store = _session.getStore();//from w w w.  ja va  2s. c o  m
    _store.connect(_host, _userName, _password);
    if (!_store.isConnected()) {
        System.out.println("Connected not possible");
    }
    _folderName = "INBOX"; // TODO
    _folder = _store.getFolder(_folderName);
    _folder.open(Folder.READ_ONLY);

    System.out.println("//////////Folder open!/////");

    InputStream answer = null;

    //channel parameter bekommen
    String sender = "support@jevis.de";
    String subject = "testinfo";
    Date lastReadout = new Date(1459658993827L);
    System.out.println("channel parameters: " + sender + " " + subject + " " + lastReadout);
    //richtige E-Mail(-s) finden
    SearchTerm newerThan = new ReceivedDateTerm(ComparisonTerm.GT, lastReadout);
    SearchTerm senderTerm = null;
    try {
        senderTerm = new FromTerm(new InternetAddress(sender));
    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SearchTerm subjectTerm = new SubjectTerm(subject);
    SearchTerm andTerm = new AndTerm(newerThan, new AndTerm(senderTerm, subjectTerm));
    System.out.println(andTerm.toString());
    List<Message> messageList = null;
    try {
        messageList = Arrays.asList(_folder.search(andTerm));
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //
    _folder.close(false);
    System.out.println("Folder closed");
    _store.close();
    System.out.println("Store closed");

    /**
     * List<File> attachments = new ArrayList<File>(); for (Message message
     * : messageList) { try { Multipart multipart = (Multipart)
     * message.getContent(); for (int i = 0; i < multipart.getCount(); i++)
     * { BodyPart bodyPart = multipart.getBodyPart(i); if
     * (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) &&
     * !StringUtils.isNotBlank(bodyPart.getFileName())) { // !Checks if a
     * String is not empty (""), not null and not whitespace only. continue;
     * // dealing with attachments only } InputStream is =
     * bodyPart.getInputStream(); File file = new File("/tmp/" +
     * bodyPart.getFileName()); FileOutputStream fos = new
     * FileOutputStream(file); byte[] buf = new byte[4096]; int bytesRead;
     * while ((bytesRead = is.read(buf)) != -1) { fos.write(buf, 0,
     * bytesRead); } fos.close(); attachments.add(file);
        }*
     */

    /*for (int i = 0; i < answerList.size(); i++) {
        System.out.print(answerList.get(i).toString());
        }*/
}