List of usage examples for javax.mail MessagingException printStackTrace
public void printStackTrace()
From source file:FolderModel.java
protected String[] getCachedData(int row) { if (cached[row] == null) { try {//from w w w . jav a 2s .co m Message m = messages[row]; String[] theData = new String[4]; // Date Date date = m.getSentDate(); if (date == null) { theData[0] = "Unknown"; } else { theData[0] = date.toString(); } // From Address[] adds = m.getFrom(); if (adds != null && adds.length != 0) { theData[1] = adds[0].toString(); } else { theData[1] = ""; } // Subject String subject = m.getSubject(); if (subject != null) { theData[2] = subject; } else { theData[2] = "(No Subject)"; } cached[row] = theData; } catch (MessagingException e) { e.printStackTrace(); } } return cached[row]; }
From source file:Sender.java
/** Do the work: send the mail to the SMTP server. */ public void doSend() { // We need to pass info to the mail server as a Properties, since // JavaMail (wisely) allows room for LOTS of properties... Properties props = new Properties(); // Your LAN must define the local SMTP server as "mailhost" // for this simple-minded version to be able to send mail... props.put("mail.smtp.host", "mailhost"); // Create the Session object session = Session.getDefaultInstance(props, null); session.setDebug(true); // Verbose! try {/*from w w w .j a v a 2 s . c o m*/ // create a message mesg = new MimeMessage(session); // From Address - this should come from a Properties... mesg.setFrom(new InternetAddress("nobody@host.domain")); // TO Address InternetAddress toAddress = new InternetAddress(message_recip); mesg.addRecipient(Message.RecipientType.TO, toAddress); // CC Address InternetAddress ccAddress = new InternetAddress(message_cc); mesg.addRecipient(Message.RecipientType.CC, ccAddress); // The Subject mesg.setSubject(message_subject); // Now the message body. mesg.setText(message_body); // XXX I18N: use setText(msgText.getText(), charset) // Finally, send the message! Transport.send(mesg); } catch (MessagingException ex) { while ((ex = (MessagingException) ex.getNextException()) != null) { ex.printStackTrace(); } } }
From source file:de.metas.procurement.webui.service.impl.LoginService.java
@Override public void sendPasswordResetKey(final String email, final URI passwordResetURI) { Preconditions.checkNotNull(passwordResetURI, "passwordResetURI is null"); MimeMessage mail = emailSender.createMimeMessage(); try {/* w w w. j av a2 s . c o m*/ MimeMessageHelper helper = new MimeMessageHelper(mail, true); // multipart=true if (emailFrom != null && !emailFrom.trim().isEmpty()) { helper.setFrom(emailFrom.trim()); } helper.setTo(email); helper.setSubject(i18n.get("PasswordReset.email.subject")); helper.setText(i18n.get("PasswordReset.email.content", passwordResetURI)); } catch (MessagingException e) { e.printStackTrace(); } finally { } emailSender.send(mail); }
From source file:org.blue.star.plugins.send_mail.java
public boolean execute_check() { Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); if (smtpAuth) { props.put("mail.smtp.auth", "true"); }/*from w w w. j av a 2 s. c om*/ Session session = Session.getInstance(props, null); SMTPTransport transport = null; // if (debug) // session.setDebug(true); // construct the message try { Message msg = new MimeMessage(session); if (from != null) msg.setFrom(new InternetAddress(from)); else msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); if (subject != null) msg.setSubject(subject); msg.setHeader("X-Mailer", "blue-send-mail"); msg.setSentDate(new Date()); msg.setText(message.replace("\\n", "\n").replace("\\t", "\t")); transport = (SMTPTransport) session.getTransport(ssl ? "smtps" : "smtp"); if (smtpAuth) transport.connect(smtpServer, smtpUser, smtpPass); else transport.connect(); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); } catch (MessagingException mE) { mE.printStackTrace(); this.state = common_h.STATE_CRITICAL; this.text = mE.getMessage(); return false; } finally { try { transport.close(); } catch (Exception e) { } } state = common_h.STATE_OK; text = "Message Sent!"; return true; }
From source file:org.smartloli.kafka.eagle.api.email.MailServiceImpl.java
/** Send mail in HTML format */ private boolean sendHtmlMail(MailSenderInfo mailInfo) { boolean enableMailAlert = SystemConfigUtils.getBooleanProperty("kafka.eagle.mail.enable"); if (enableMailAlert) { SaAuthenticatorInfo authenticator = null; Properties pro = mailInfo.getProperties(); if (mailInfo.isValidate()) { authenticator = new SaAuthenticatorInfo(mailInfo.getUserName(), mailInfo.getPassword()); }//ww w .j a v a2s. c o m Session sendMailSession = Session.getDefaultInstance(pro, authenticator); try { Message mailMessage = new MimeMessage(sendMailSession); Address from = new InternetAddress(mailInfo.getFromAddress()); mailMessage.setFrom(from); Address[] to = new Address[mailInfo.getToAddress().split(",").length]; int i = 0; for (String e : mailInfo.getToAddress().split(",")) to[i++] = new InternetAddress(e); mailMessage.setRecipients(Message.RecipientType.TO, to); mailMessage.setSubject(mailInfo.getSubject()); mailMessage.setSentDate(new Date()); Multipart mainPart = new MimeMultipart(); BodyPart html = new MimeBodyPart(); html.setContent(mailInfo.getContent(), "text/html; charset=UTF-8"); mainPart.addBodyPart(html); if (mailInfo.getImagesMap() != null && !mailInfo.getImagesMap().isEmpty()) { for (Entry<String, String> entry : mailInfo.getImagesMap().entrySet()) { MimeBodyPart mbp = new MimeBodyPart(); File file = new File(entry.getValue()); FileDataSource fds = new FileDataSource(file); mbp.setDataHandler(new DataHandler(fds)); try { mbp.setFileName(MimeUtility.encodeWord(entry.getKey(), "UTF-8", null)); } catch (Exception e) { e.printStackTrace(); } mbp.setContentID(entry.getKey()); mbp.setHeader("Content-ID", "<image>"); mainPart.addBodyPart(mbp); } } List<File> list = mailInfo.getFileList(); if (list != null && list.size() > 0) { for (File f : list) { MimeBodyPart mbp = new MimeBodyPart(); FileDataSource fds = new FileDataSource(f.getAbsolutePath()); mbp.setDataHandler(new DataHandler(fds)); mbp.setFileName(f.getName()); mainPart.addBodyPart(mbp); } list.clear(); } mailMessage.setContent(mainPart); // mailMessage.saveChanges(); Transport.send(mailMessage); return true; } catch (MessagingException ex) { ex.printStackTrace(); } } return false; }
From source file:Sender2.java
/** * Send the file with no filename, assuming you've already called the * setBody() method.//from w w w . jav a2 s . c om */ public void sendFile() { try { // Finally, send the message! (use static Transport method) Transport.send(mesg); } catch (MessagingException ex) { while ((ex = (MessagingException) ex.getNextException()) != null) { ex.printStackTrace(); } } }
From source file:MultipartViewer.java
protected void setupDisplay(Multipart mp) { // we display the first body part in a main frame on the left, and then // on the right we display the rest of the parts as attachments GridBagConstraints gc = new GridBagConstraints(); gc.gridheight = GridBagConstraints.REMAINDER; gc.fill = GridBagConstraints.BOTH; gc.weightx = 1.0;/* w w w .j a v a 2 s.c o m*/ gc.weighty = 1.0; // get the first part try { BodyPart bp = mp.getBodyPart(0); Component comp = getComponent(bp); add(comp, gc); } catch (MessagingException me) { add(new Label(me.toString()), gc); } // see if there are more than one parts try { int count = mp.getCount(); // setup how to display them gc.gridwidth = GridBagConstraints.REMAINDER; gc.gridheight = 1; gc.fill = GridBagConstraints.NONE; gc.anchor = GridBagConstraints.NORTH; gc.weightx = 0.0; gc.weighty = 0.0; gc.insets = new Insets(4, 4, 4, 4); // for each one we create a button with the content type for (int i = 1; i < count; i++) { // we skip the first one BodyPart curr = mp.getBodyPart(i); String label = null; if (label == null) label = curr.getFileName(); if (label == null) label = curr.getDescription(); if (label == null) label = curr.getContentType(); Button but = new Button(label); but.addActionListener(new AttachmentViewer(curr)); add(but, gc); } } catch (MessagingException me2) { me2.printStackTrace(); } }
From source file:com.asptt.plongee.resa.service.AdherentServiceTest.java
public void envoyerMail() throws TechnicalException { // donnes pour le test try {/*from w w w . j a v a 2 s .c om*/ Adherent adherent = adherentService.rechercherAdherentParIdentifiant("444444"); Plongee plongee = plongeeService.rechercherPlongeeParId(26); // Email eMail = new SimpleEmail(); // eMail.setSubject("gestion de file d'attente"); // eMail.setMsg("Mille excuses...\n ca se voulait un test de liste de diffusion, mais a n'aurait pas du partir...\n A bientot \n Eric"); // List<String> destis = new ArrayList<String>(); // destis.add("eric.simon28@orange.fr"); PlongeeMail pMail = new PlongeeMail(PlongeeMail.MAIL_INSCRIPTION_SUR_PLONGEE_FERMEE, plongee, adherent); pMail.sendMail("ADMIN"); } catch (ResaException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:com.gst.infrastructure.reportmailingjob.service.ReportMailingJobEmailServiceImpl.java
@Override public void sendEmailWithAttachment(ReportMailingJobEmailData reportMailingJobEmailData) { try {/*from w ww . j a v a 2 s . co m*/ // get all ReportMailingJobConfiguration objects from the database this.reportMailingJobConfigurationDataCollection = this.reportMailingJobConfigurationReadPlatformService .retrieveAllReportMailingJobConfigurations(); JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); javaMailSenderImpl.setHost(this.getGmailSmtpServer()); javaMailSenderImpl.setPort(this.getGmailSmtpPort()); javaMailSenderImpl.setUsername(this.getGmailSmtpUsername()); javaMailSenderImpl.setPassword(this.getGmailSmtpPassword()); javaMailSenderImpl.setJavaMailProperties(this.getJavaMailProperties()); MimeMessage mimeMessage = javaMailSenderImpl.createMimeMessage(); // use the true flag to indicate you need a multipart message MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setTo(reportMailingJobEmailData.getTo()); mimeMessageHelper.setText(reportMailingJobEmailData.getText()); mimeMessageHelper.setSubject(reportMailingJobEmailData.getSubject()); if (reportMailingJobEmailData.getAttachment() != null) { mimeMessageHelper.addAttachment(reportMailingJobEmailData.getAttachment().getName(), reportMailingJobEmailData.getAttachment()); } javaMailSenderImpl.send(mimeMessage); } catch (MessagingException e) { // handle the exception e.printStackTrace(); } }
From source file:org.mifosplatform.infrastructure.reportmailingjob.service.ReportMailingJobEmailServiceImpl.java
@Override public void sendEmailWithAttachment(ReportMailingJobEmailData reportMailingJobEmailData) { try {// w w w.ja v a 2 s. c o m // get all ReportMailingJobConfiguration objects from the database this.reportMailingJobConfigurationDataCollection = this.reportMailingJobConfigurationReadPlatformService .retrieveAllReportMailingJobConfigurations(); JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); javaMailSenderImpl.setHost(this.getReportSmtpServer()); javaMailSenderImpl.setPort(this.getRerportSmtpPort()); javaMailSenderImpl.setUsername(this.getReportSmtpUsername()); javaMailSenderImpl.setPassword(this.getReportSmtpPassword()); javaMailSenderImpl.setJavaMailProperties(this.getJavaMailProperties()); MimeMessage mimeMessage = javaMailSenderImpl.createMimeMessage(); // use the true flag to indicate you need a multipart message MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setTo(reportMailingJobEmailData.getTo()); mimeMessageHelper.setFrom(this.getReportSmtpFromAddress()); mimeMessageHelper.setText(reportMailingJobEmailData.getText()); mimeMessageHelper.setSubject(reportMailingJobEmailData.getSubject()); if (reportMailingJobEmailData.getAttachment() != null) { mimeMessageHelper.addAttachment(reportMailingJobEmailData.getAttachment().getName(), reportMailingJobEmailData.getAttachment()); } javaMailSenderImpl.send(mimeMessage); } catch (MessagingException e) { // handle the exception e.printStackTrace(); } }