Search in sources :

Example 21 with AddressException

use of javax.mail.internet.AddressException in project jmeter by apache.

the class MailerVisualizer method actionPerformed.

// ////////////////////////////////////////////////////////////
//
// Implementation of the ActionListener-Interface.
//
// ////////////////////////////////////////////////////////////
/**
     * Reacts on an ActionEvent (like pressing a button).
     *
     * @param e
     *            The ActionEvent with information about the event and its
     *            source.
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == testerButton) {
        ResultCollector testElement = getModel();
        modifyTestElement(testElement);
        try {
            MailerModel model = ((MailerResultCollector) testElement).getMailerModel();
            model.sendTestMail();
            //$NON-NLS-1$
            displayMessage(JMeterUtils.getResString("mail_sent"), false);
        } catch (AddressException ex) {
            log.error("Invalid mail address ", ex);
            displayMessage(//$NON-NLS-1$
            JMeterUtils.getResString("invalid_mail_address") + "\n" + ex.getMessage(), //$NON-NLS-1$
            true);
        } catch (MessagingException ex) {
            log.error("Couldn't send mail...", ex);
            displayMessage(//$NON-NLS-1$
            JMeterUtils.getResString("invalid_mail") + "\n" + ex.getMessage(), //$NON-NLS-1$
            true);
        }
    }
}
Also used : MailerResultCollector(org.apache.jmeter.reporters.MailerResultCollector) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) MailerModel(org.apache.jmeter.reporters.MailerModel) MailerResultCollector(org.apache.jmeter.reporters.MailerResultCollector) ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Example 22 with AddressException

use of javax.mail.internet.AddressException in project JMRI by JMRI.

the class ReportPanel method sendButtonActionPerformed.

@SuppressWarnings("unchecked")
public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    try {
        sendButton.setEnabled(false);
        log.debug("initial checks");
        InternetAddress email = new InternetAddress(emailField.getText());
        email.validate();
        log.debug("start send");
        //NO18N
        String charSet = "UTF-8";
        //NOI18N
        String requestURL = "http://jmri.org/problem-report.php";
        MultipartMessage msg = new MultipartMessage(requestURL, charSet);
        // add reporter email address
        log.debug("start creating message");
        msg.addFormField("reporter", emailField.getText());
        // add if to Cc sender
        msg.addFormField("sendcopy", checkCopy.isSelected() ? "yes" : "no");
        // add problem summary
        msg.addFormField("summary", summaryField.getText());
        // build detailed error report (include context if selected)
        String report = descField.getText() + "\r\n";
        if (checkContext.isSelected()) {
            //NOI18N
            report += "=========================================================\r\n";
            report += (new ReportContext()).getReport(checkNetwork.isSelected() && checkNetwork.isEnabled());
        }
        msg.addFormField("problem", report);
        log.debug("start adding attachments");
        // add panel file if OK
        if (checkPanel.isSelected()) {
            log.debug("prepare panel attachment");
            // Check that some startup panel files have been loaded
            for (PerformFileModel m : InstanceManager.getDefault(StartupActionsManager.class).getActions(PerformFileModel.class)) {
                String fn = m.getFileName();
                File f = new File(fn);
                log.debug("add startup panel file: {}", f);
                msg.addFilePart("logfileupload[]", f);
            }
            // Check that a manual panel file has been loaded
            File file = jmri.configurexml.LoadXmlUserAction.getCurrentFile();
            if (file != null) {
                log.debug("add manual panel file: {}", file.getPath());
                msg.addFilePart("logfileupload[]", jmri.configurexml.LoadXmlUserAction.getCurrentFile());
            } else {
                // No panel file loaded
                log.warn("No manual panel file loaded - not sending");
            }
        }
        // add profile files if OK
        if (checkProfile.isSelected()) {
            log.debug("prepare profile attachment");
            // Check that a profile has been loaded
            Profile profile = ProfileManager.getDefault().getActiveProfile();
            File file = profile.getPath();
            if (file != null) {
                log.debug("add profile: {}", file.getPath());
                // Now zip-up contents of profile
                // Create temp file that will be deleted when Java quits
                File temp = File.createTempFile("profile", ".zip");
                temp.deleteOnExit();
                FileOutputStream out = new FileOutputStream(temp);
                ZipOutputStream zip = new ZipOutputStream(out);
                addDirectory(zip, file);
                zip.close();
                out.close();
                msg.addFilePart("logfileupload[]", temp);
            } else {
                // No profile loaded
                log.warn("No profile loaded - not sending");
            }
        }
        // add the log if OK
        if (checkLog.isSelected()) {
            log.debug("prepare log attachments");
            // search for an appender that stores a file
            for (java.util.Enumeration<org.apache.log4j.Appender> en = org.apache.log4j.Logger.getRootLogger().getAllAppenders(); en.hasMoreElements(); ) {
                // does this have a file?
                org.apache.log4j.Appender a = en.nextElement();
                // see if it's one of the ones we know
                if (log.isDebugEnabled()) {
                    log.debug("check appender {}", a);
                }
                try {
                    org.apache.log4j.FileAppender f = (org.apache.log4j.FileAppender) a;
                    log.debug("find file: {}", f.getFile());
                    msg.addFilePart("logfileupload[]", new File(f.getFile()), "application/octet-stream");
                } catch (ClassCastException ex) {
                }
            }
        }
        log.debug("done adding attachments");
        // finalise and get server response (if any)
        log.debug("posting report...");
        List<String> response = msg.finish();
        log.debug("send complete");
        log.debug("server response:");
        boolean checkResponse = false;
        for (String line : response) {
            log.debug("               :{}", line);
            if (line.contains("<p>Message successfully sent!</p>")) {
                checkResponse = true;
            }
        }
        if (checkResponse) {
            JOptionPane.showMessageDialog(null, rb.getString("InfoMessage"), rb.getString("InfoTitle"), JOptionPane.INFORMATION_MESSAGE);
            // close containing Frame
            getTopLevelAncestor().setVisible(false);
        } else {
            // TODO add Bundle to folder and use ErrorTitle key in NamedBeanBundle props
            JOptionPane.showMessageDialog(null, rb.getString("ErrMessage"), rb.getString("ErrTitle"), JOptionPane.ERROR_MESSAGE);
            sendButton.setEnabled(true);
        }
    } catch (IOException ex) {
        log.error("Error when attempting to send report: " + ex);
        sendButton.setEnabled(true);
    } catch (AddressException ex) {
        log.error("Invalid email address: " + ex);
        // TODO add Bundle to folder and use ErrorTitle key in NamedBeanBundle props
        JOptionPane.showMessageDialog(null, rb.getString("ErrAddress"), rb.getString("ErrTitle"), JOptionPane.ERROR_MESSAGE);
        sendButton.setEnabled(true);
    }
}
Also used : MultipartMessage(jmri.util.MultipartMessage) InternetAddress(javax.mail.internet.InternetAddress) StartupActionsManager(apps.StartupActionsManager) IOException(java.io.IOException) Profile(jmri.profile.Profile) PerformFileModel(apps.PerformFileModel) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) AddressException(javax.mail.internet.AddressException) File(java.io.File)

Example 23 with AddressException

use of javax.mail.internet.AddressException in project nhin-d by DirectProject.

the class MessageServiceImplService method requestStatus.

@Override
public StatusResponseType requestStatus(StatusRefType body) {
    List<String> msgs = body.getMessageID();
    StatusResponseType response = new StatusResponseType();
    try {
        checkAuth(response);
        Authenticator auth = new SMTPAuthenticator();
        Session session = Session.getInstance(imapProps, auth);
        session.setDebug(true);
        if (msgs.size() > 0) {
            Store store = session.getStore(new javax.mail.URLName("imaps://" + username));
            store.connect(getImapHost(), Integer.valueOf(getImapPort()).intValue(), username, password);
            for (int x = 0; x < msgs.size(); x++) {
                String msgid = msgs.get(x);
                MessageIDTerm messageIdTerm = new MessageIDTerm(msgid);
                IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
                folder.open(Folder.READ_ONLY);
                SearchTerm st = messageIdTerm;
                IMAPMessage[] msgsearch = (IMAPMessage[]) folder.search(st);
                if (msgsearch.length > 0) {
                    Flags flags = msgsearch[0].getFlags();
                    Flag[] inboxflags = flags.getSystemFlags();
                    String[] listofflags = new String[inboxflags.length];
                    listofflags = setSystemFlags(inboxflags);
                    setMessageIdStatus(msgid, listofflags, response.getMessageIDAndStatus());
                }
            }
        }
    } catch (AddressException e) {
        log.error(e);
    } catch (MessagingException e) {
        log.error(e);
    } catch (Exception e) {
        log.error(e);
    }
    return response;
}
Also used : MessageIDTerm(javax.mail.search.MessageIDTerm) MessagingException(javax.mail.MessagingException) IMAPFolder(com.sun.mail.imap.IMAPFolder) Store(javax.mail.Store) Flags(javax.mail.Flags) SearchTerm(javax.mail.search.SearchTerm) Flag(javax.mail.Flags.Flag) StatusResponseType(org.nhindirect.schema.edge.ws.StatusResponseType) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) IOException(java.io.IOException) AddressException(javax.mail.internet.AddressException) IMAPMessage(com.sun.mail.imap.IMAPMessage) Authenticator(javax.mail.Authenticator) Session(javax.mail.Session)

Example 24 with AddressException

use of javax.mail.internet.AddressException in project che by eclipse.

the class GitHubOAuthAuthenticator method getUser.

@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
    GitHubUser user = getJson("https://api.github.com/user?access_token=" + accessToken.getToken(), GitHubUser.class);
    GithubEmail[] result = getJson2("https://api.github.com/user/emails?access_token=" + accessToken.getToken(), GithubEmail[].class, null);
    GithubEmail verifiedEmail = null;
    for (GithubEmail email : result) {
        if (email.isPrimary() && email.isVerified()) {
            verifiedEmail = email;
            break;
        }
    }
    if (verifiedEmail == null || verifiedEmail.getEmail() == null || verifiedEmail.getEmail().isEmpty()) {
        throw new OAuthAuthenticationException("Sorry, we failed to find any verified emails associated with your GitHub account." + " Please, verify at least one email in your GitHub account and try to connect with GitHub again.");
    }
    user.setEmail(verifiedEmail.getEmail());
    final String email = user.getEmail();
    try {
        new InternetAddress(email).validate();
    } catch (AddressException e) {
        throw new OAuthAuthenticationException(e.getMessage());
    }
    return user;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException)

Example 25 with AddressException

use of javax.mail.internet.AddressException in project hudson-2.x by hudson.

the class BaseBuildResultMail method createEmptyMail.

/**
     * Creates empty mail.
     *
     * @param build build.
     * @param listener listener.
     * @return empty mail.
     * @throws MessagingException exception if any.
     */
protected MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
    MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
    // TODO: I'd like to put the URL to the page in here,
    // but how do I obtain that?
    msg.setContent("", "text/plain");
    msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
    msg.setSentDate(new Date());
    Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
    StringTokenizer tokens = new StringTokenizer(getRecipients());
    while (tokens.hasMoreTokens()) {
        String address = tokens.nextToken();
        if (address.startsWith("upstream-individuals:")) {
            // people who made a change in the upstream
            String projectName = address.substring("upstream-individuals:".length());
            AbstractProject up = Hudson.getInstance().getItemByFullName(projectName, AbstractProject.class);
            if (up == null) {
                listener.getLogger().println("No such project exist: " + projectName);
                continue;
            }
            includeCulpritsOf(up, build, listener, rcp);
        } else {
            // ordinary address
            try {
                rcp.add(new InternetAddress(address));
            } catch (AddressException e) {
                // report bad address, but try to send to other addresses
                e.printStackTrace(listener.error(e.getMessage()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(upstreamProjects)) {
        for (AbstractProject project : upstreamProjects) {
            includeCulpritsOf(project, build, listener, rcp);
        }
    }
    if (sendToIndividuals) {
        Set<User> culprits = build.getCulprits();
        if (debug)
            listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)==" + culprits.size());
        rcp.addAll(buildCulpritList(listener, culprits));
    }
    msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
    AbstractBuild<?, ?> pb = build.getPreviousBuild();
    if (pb != null) {
        MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
        if (b != null) {
            msg.setHeader("In-Reply-To", b.messageId);
            msg.setHeader("References", b.messageId);
        }
    }
    return msg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternetAddress(javax.mail.internet.InternetAddress) User(hudson.model.User) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) Date(java.util.Date) MailMessageIdAction(hudson.tasks.MailMessageIdAction) StringTokenizer(java.util.StringTokenizer) MimeMessage(javax.mail.internet.MimeMessage) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) AddressException(javax.mail.internet.AddressException) AbstractProject(hudson.model.AbstractProject)

Aggregations

AddressException (javax.mail.internet.AddressException)46 InternetAddress (javax.mail.internet.InternetAddress)37 MimeMessage (javax.mail.internet.MimeMessage)18 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)17 MessagingException (javax.mail.MessagingException)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)7 Address (javax.mail.Address)7 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 Properties (java.util.Properties)4 Session (javax.mail.Session)4 MimeBodyPart (javax.mail.internet.MimeBodyPart)4 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 Invite (com.zimbra.cs.mailbox.calendar.Invite)3 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)3 Locale (java.util.Locale)3