List of usage examples for javax.mail.internet AddressException printStackTrace
public void printStackTrace(PrintStream s)
From source file:org.jenkinsci.plugins.send_mail_builder.SendMailBuilder.java
private static final InternetAddress[] toInternetAddresses(final BuildListener listener, final String addresses, final String charset) throws UnsupportedEncodingException { final String defaultSuffix = Mailer.descriptor().getDefaultSuffix(); final Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>(); final StringTokenizer tokens = new StringTokenizer(addresses); while (tokens.hasMoreTokens()) { String address = tokens.nextToken(); // if not a valid address (i.e. no '@'), then try adding suffix if (!address.contains("@") && defaultSuffix != null && defaultSuffix.contains("@")) { address += defaultSuffix;// w ww . j a va 2 s.c o m } try { rcp.add(Mailer.StringToAddress(address, charset)); } catch (final AddressException e) { // report bad address, but try to send to other addresses listener.getLogger().println("Unable to send to address: " + address); e.printStackTrace(listener.error(e.getMessage())); } } return rcp.toArray(new InternetAddress[0]); }
From source file:hudson.tasks.mail.impl.BaseBuildResultMail.java
/** * Creates empty mail.//ww w. ja v a 2 s .com * * @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; }
From source file:edu.harvard.iq.dataverse.MailServiceBean.java
public void sendMail(String host, String from, String to, String subject, String messageText) { Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null); try {//from w w w. j a v a 2s. c o m MimeMessage msg = new MimeMessage(session); String[] recipientStrings = to.split(","); InternetAddress[] recipients = new InternetAddress[recipientStrings.length]; try { msg.setFrom(new InternetAddress(from, charset)); for (int i = 0; i < recipients.length; i++) { recipients[i] = new InternetAddress(recipientStrings[i], "", charset); } } catch (UnsupportedEncodingException ex) { logger.severe(ex.getMessage()); } msg.setRecipients(Message.RecipientType.TO, recipients); msg.setSubject(subject, charset); msg.setText(messageText, charset); Transport.send(msg, recipients); } catch (AddressException ae) { ae.printStackTrace(System.out); } catch (MessagingException me) { me.printStackTrace(System.out); } }
From source file:edu.harvard.iq.dataverse.MailServiceBean.java
public void sendMail(String from, String to, String subject, String messageText, Map<Object, Object> extraHeaders) { try {/*from ww w . j av a2 s .co m*/ MimeMessage msg = new MimeMessage(session); if (from.matches(EMAIL_PATTERN)) { msg.setFrom(new InternetAddress(from)); } else { // set fake from address; instead, add it as part of the message //msg.setFrom(new InternetAddress("invalid.email.address@mailinator.com")); msg.setFrom(getSystemAddress()); messageText = "From: " + from + "\n\n" + messageText; } msg.setSentDate(new Date()); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); msg.setSubject(subject, charset); msg.setText(messageText, charset); if (extraHeaders != null) { for (Object key : extraHeaders.keySet()) { String headerName = key.toString(); String headerValue = extraHeaders.get(key).toString(); msg.addHeader(headerName, headerValue); } } Transport.send(msg); } catch (AddressException ae) { ae.printStackTrace(System.out); } catch (MessagingException me) { me.printStackTrace(System.out); } }
From source file:edu.harvard.iq.dataverse.MailServiceBean.java
public boolean sendSystemEmail(String to, String subject, String messageText) { boolean sent = false; String rootDataverseName = dataverseService.findRootDataverse().getName(); String body = messageText + BundleUtil.getStringFromBundle("notification.email.closing", Arrays.asList(BrandingUtil.getInstallationBrandName(rootDataverseName))); logger.fine("Sending email to " + to + ". Subject: <<<" + subject + ">>>. Body: " + body); try {/*from w ww.ja v a2s . c o m*/ MimeMessage msg = new MimeMessage(session); InternetAddress systemAddress = getSystemAddress(); if (systemAddress != null) { msg.setFrom(systemAddress); msg.setSentDate(new Date()); String[] recipientStrings = to.split(","); InternetAddress[] recipients = new InternetAddress[recipientStrings.length]; for (int i = 0; i < recipients.length; i++) { try { recipients[i] = new InternetAddress('"' + recipientStrings[i] + '"', "", charset); } catch (UnsupportedEncodingException ex) { logger.severe(ex.getMessage()); } } msg.setRecipients(Message.RecipientType.TO, recipients); msg.setSubject(subject, charset); msg.setText(body, charset); try { Transport.send(msg, recipients); sent = true; } catch (SMTPSendFailedException ssfe) { logger.warning("Failed to send mail to " + to + " (SMTPSendFailedException)"); } } else { logger.fine("Skipping sending mail to " + to + ", because the \"no-reply\" address not set (" + Key.SystemEmail + " setting)."); } } catch (AddressException ae) { logger.warning("Failed to send mail to " + to); ae.printStackTrace(System.out); } catch (MessagingException me) { logger.warning("Failed to send mail to " + to); me.printStackTrace(System.out); } return sent; }
From source file:hudson.tasks.MailSender.java
private MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException, UnsupportedEncodingException { MimeMessage msg = new MimeMessage(Mailer.descriptor().createSession()); // TODO: I'd like to put the URL to the page in here, // but how do I obtain that? msg.addHeader("X-Jenkins-Job", build.getProject().getDisplayName()); msg.addHeader("X-Jenkins-Result", build.getResult().toString()); msg.setContent("", "text/plain"); msg.setFrom(Mailer.StringToAddress(Mailer.descriptor().getAdminAddress(), charset)); msg.setSentDate(new Date()); String replyTo = Mailer.descriptor().getReplyToAddress(); if (StringUtils.isNotBlank(replyTo)) { msg.setReplyTo(new Address[] { Mailer.StringToAddress(replyTo, charset) }); }//from ww w . j a v a 2 s .c o m Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>(); String defaultSuffix = Mailer.descriptor().getDefaultSuffix(); StringTokenizer tokens = new StringTokenizer(recipients); 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 = Jenkins.getInstance().getItem(projectName, build.getProject(), AbstractProject.class); if (up == null) { listener.getLogger().println("No such project exist: " + projectName); continue; } includeCulpritsOf(up, build, listener, rcp); } else { // ordinary address // if not a valid address (i.e. no '@'), then try adding suffix if (!address.contains("@") && defaultSuffix != null && defaultSuffix.contains("@")) { address += defaultSuffix; } try { rcp.add(Mailer.StringToAddress(address, charset)); } catch (AddressException e) { // report bad address, but try to send to other addresses listener.getLogger().println("Unable to send to address: " + address); e.printStackTrace(listener.error(e.getMessage())); } } } for (AbstractProject project : includeUpstreamCommitters) { 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; }