List of usage examples for javax.mail.internet InternetAddress parse
public static InternetAddress[] parse(String addresslist) throws AddressException
From source file:gov.nih.nci.cacis.cdw.CDWPendingLoader.java
public void loadPendingCDWDocuments(CDWLoader loader) { LOG.debug("Pending folder: " + cdwLoadPendingDirectory); LOG.info("SSSSSSS STARTED CDW LOAD SSSSSSSS"); File pendingFolder = new File(cdwLoadPendingDirectory); FilenameFilter loadFileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return true; }/* ww w . j a v a2 s .co m*/ }; String[] loadFileNames = pendingFolder.list(loadFileFilter); LOG.info("Total Files to Load: " + loadFileNames.length); int filesLoaded = 0; int fileNumber = 0; for (String fileName : loadFileNames) { fileNumber++; LOG.info("Processing File [" + fileNumber + "] " + fileName); File loadFile = new File(cdwLoadPendingDirectory + "/" + fileName); try { final String[] params = StringUtils.split(fileName, "@@"); String siteId = params[0]; String studyId = params[1]; String patientId = params[2]; LOG.debug("SiteId: " + siteId); // the below code is not working, so parsing the file name for attributes. // DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); // DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); // Document document = documentBuilder.parse(loadFile); // XPathFactory factory = XPathFactory.newInstance(); // XPath xPath = factory.newXPath(); // String siteID = xPath.evaluate("/caCISRequest/clinicalMetaData/@siteIdRoot", document); loader.load(FileUtils.getStringFromFile(loadFile), loader.generateContext(), studyId, siteId, patientId); LOG.info(String.format("Successfully processed file [%s] [%s] and moving into [%s]", fileNumber, loadFile.getAbsolutePath(), cdwLoadProcessedDirectory)); org.apache.commons.io.FileUtils.moveFileToDirectory(loadFile, new File(cdwLoadProcessedDirectory), true); filesLoaded++; } catch (Exception e) { LOG.error(e.getMessage()); e.printStackTrace(); try { Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", cdwLoadSenderHost); props.put("mail.smtp.port", cdwLoadSenderPort); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(cdwLoadSenderUser, cdwLoadSenderPassword); } }); Message message = new MimeMessage(session); message.setFrom(new InternetAddress(cdwLoadSenderAddress)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(cdwLoadRecipientAddress)); message.setSubject(cdwLoadNotificationSubject); message.setText(cdwLoadNotificationMessage + " [" + e.getMessage() + "]"); Transport.send(message); org.apache.commons.io.FileUtils.moveFileToDirectory(loadFile, new File(cdwLoadErrorDirectory), true); // TODO add logic to send email } catch (Exception e1) { LOG.error(e1.getMessage()); e1.printStackTrace(); } } } LOG.info("Files Successfully Loaded: " + filesLoaded); LOG.info("EEEEEEE ENDED CDW LOAD EEEEEEE"); }
From source file:org.libreplan.importers.notifications.ComposeMessage.java
public boolean composeMessageForUser(EmailNotification notification) { // Gather data about EmailTemplate needs to be used Resource resource = notification.getResource(); EmailTemplateEnum type = notification.getType(); Locale locale;//from w w w . j a v a2 s . c om Worker currentWorker = getCurrentWorker(resource.getId()); UserRole currentUserRole = getCurrentUserRole(notification.getType()); if (currentWorker != null && currentWorker.getUser().isInRole(currentUserRole)) { if (currentWorker.getUser().getApplicationLanguage().equals(Language.BROWSER_LANGUAGE)) { locale = new Locale(System.getProperty("user.language")); } else { locale = new Locale(currentWorker.getUser().getApplicationLanguage().getLocale().getLanguage()); } EmailTemplate currentEmailTemplate = findCurrentEmailTemplate(type, locale); if (currentEmailTemplate == null) { LOG.error("Email template is null"); return false; } // Modify text that will be composed String text = currentEmailTemplate.getContent(); text = replaceKeywords(text, currentWorker, notification); String receiver = currentWorker.getUser().getEmail(); setupConnectionProperties(); final String username = usrnme; final String password = psswrd; // It is very important to use Session.getInstance() instead of Session.getDefaultInstance() Session mailSession = Session.getInstance(properties, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); // Send message try { MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(sender)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver)); String subject = currentEmailTemplate.getSubject(); message.setSubject(subject); message.setText(text); Transport.send(message); return true; } catch (MessagingException e) { throw new RuntimeException(e); } catch (NullPointerException e) { if (receiver == null) { Messagebox.show( _(currentWorker.getUser().getLoginName() + " - this user have not filled E-mail"), _("Error"), Messagebox.OK, Messagebox.ERROR); } } } return false; }
From source file:org.data2semantics.yasgui.selenium.FailNotification.java
private void sendMail(String subject, String content, String fileName) { Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(baseTest.props.getMailUserName(), baseTest.props.getMailPassWord()); }/* w ww. j a va2 s. c om*/ }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(baseTest.props.getMailUserName())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(baseTest.props.getMailSendTo())); message.setSubject(subject); message.setContent(content, "text/html; charset=utf-8"); MimeBodyPart messageBodyPart = new MimeBodyPart(); // message body messageBodyPart.setContent(content, "text/html; charset=utf-8"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // attachment messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(fileName); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName("screenshot.png"); multipart.addBodyPart(messageBodyPart); message.setContent(multipart); Transport.send(message); System.out.println("Email send"); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:com.jvoid.customers.customer.service.CustomerMasterService.java
public void sendEmail(String email, String password) { Properties properties = System.getProperties(); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.auth", false); properties.put("mail.smtp.host", "smtp.gmail.com"); properties.put("mail.smtp.port", 587); Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("test@example.com", "test123"); }/*ww w .j a v a2 s.c o m*/ }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("toaddress@example.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Reset Password"); String content = "Your new password is " + password; message.setText(content); Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:com.mycompany.craftdemo.utility.java
public static void send(long phno, double price, double profit, String domain, String company) { HashMap<String, String> domainMap = new HashMap<>(); domainMap.put("TMobile", "tmomail.net "); domainMap.put("ATT", "txt.att.net"); domainMap.put("Sprint", "messaging.sprintpcs.com"); domainMap.put("Verizon", "vtext.com"); String to = phno + "@" + domainMap.get(domain); //change accordingly // Sender's email ID needs to be mentioned String from = "uni5prince@gmail.com"; //change accordingly final String username = "uni5prince"; //change accordingly final String password = "savageph8893"; //change accordingly // Assuming you are sending email through relay.jangosmtp.net String host = "smtp.gmail.com"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "587"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*from ww w . j av a 2s .co m*/ }); try { // Create a default MimeMessage object. Message message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Prices have gone up!!"); // Now set the actual message message.setText("Hello Jane, Stock prices for " + company + " has reached to $" + price + " with profit of $" + profit); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:com.threepillar.labs.meeting.email.EmailInviteImpl.java
@Override public void sendInvite(final String subject, final String description, final Participant from, final List<Participant> attendees, final Date startDate, final Date endDate, final String location) throws Exception { this.properties.put("mail.smtp.socketFactory.port", properties.get("mail.smtp.port")); this.properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); this.properties.put("mail.smtp.socketFactory.fallback", "false"); validate();/*w w w . j av a2s . c om*/ LOG.info("Sending meeting invite"); LOG.debug("Mail Properties :: " + this.properties); Session session; if (password != null) { session = Session.getInstance(this.properties, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); } else { session = Session.getInstance(this.properties); } ICal cal = new ICal(subject, description, from, attendees, startDate, endDate, location); cal.init(); StringBuffer sb = new StringBuffer(); sb.append(from.getEmail()); for (Participant bean : attendees) { if (sb.length() > 0) { sb.append(","); } sb.append(bean.getEmail()); } MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from.getEmail())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(sb.toString())); message.setSubject(subject); Multipart multipart = new MimeMultipart(); MimeBodyPart iCal = new MimeBodyPart(); iCal.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(cal.toByteArray()), "text/calendar;method=REQUEST;charset=\"UTF-8\""))); LOG.debug("Calender Request :: \n" + cal.toString()); multipart.addBodyPart(iCal); message.setContent(multipart); Transport.send(message); }
From source file:eagle.common.email.EagleMailClient.java
private boolean _send(String from, String to, String cc, String title, String content, List<MimeBodyPart> attachments) { MimeMessage mail = new MimeMessage(session); try {//from w w w . jav a 2 s. c om mail.setFrom(new InternetAddress(from)); mail.setSubject(title); if (to != null) { mail.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); } if (cc != null) { mail.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc)); } //mail.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(DEFAULT_BCC_ADDRESS)); MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeBodyPart.setContent(content, "text/html;charset=utf-8"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(mimeBodyPart); for (MimeBodyPart attachment : attachments) { multipart.addBodyPart(attachment); } mail.setContent(multipart); // mail.setContent(content, "text/html;charset=utf-8"); LOG.info(String.format("Going to send mail: from[%s], to[%s], cc[%s], title[%s]", from, to, cc, title)); Transport.send(mail); return true; } catch (AddressException e) { LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e); return false; } catch (MessagingException e) { LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e); return false; } }
From source file:Security.EmailSender.java
/** * Metda sendUserPasswordRecoveryEmail je ur?en na generovbanie a zaslanie pouvateovi email s obnovenm jeho zabudnutho hesla. * @param email - pouvatesk email/*from w w w . j a va 2 s. c om*/ */ public void sendUserPasswordRecoveryEmail(String email) { try { DBLoginFinder finder = new DBLoginFinder(); ArrayList<String> results = finder.getUserInformation(email); String name = "NONE"; String surname = "NONE"; if (results.get(0) != null) { name = results.get(0); } if (results.get(1) != null) { surname = results.get(1); } Properties props = new Properties(); props.put("mail.smtp.host", server); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("skuska.api.3@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Your password to GPSWebApp server!!!"); //message.setText(userToken); message.setSubject("Your password to GPSWebApp server!!!"); message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ",</h1><br>your paassword to access GPSWebApp server is <b>" + results.get(5) + "</b>. <br>Please take note that you can change it in your settings. Have a pleasant day.</body></html>", "text/html"); Transport.send(message); FileLogger.getInstance() .createNewLog("Successfuly sent password recovery email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } }
From source file:ua.aits.sdolyna.controller.MainController.java
@RequestMapping(value = { "/sendmail/", "/sendmail" }, method = RequestMethod.GET) public @ResponseBody String sendMail(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String email = request.getParameter("email"); String text = request.getParameter("text"); final String username = "office@crc.org.ua"; final String password = "crossroad2000"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected javax.mail.PasswordAuthentication getPasswordAuthentication() { return new javax.mail.PasswordAuthentication(username, password); }/*ww w .j a va2 s. com*/ }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(email)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("sonyachna-dolyna@ukr.net")); message.setSubject("E-mail ? ?:"); message.setText("?: " + name + "\nEmail: " + email + "\n\n" + text); Transport.send(message); return "done"; } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:sk.mlp.security.EmailSender.java
/** * Metda sendUserPasswordRecoveryEmail je ur?en na generovbanie a zaslanie pouvateovi email s obnovenm jeho zabudnutho hesla. * @param email - pouvatesk email// w w w . j ava 2 s.c o m */ public void sendUserPasswordRecoveryEmail(String email) { try { DatabaseServices databaseServices = new DatabaseServices(); User user = databaseServices.findUserByEmail(email); String name = "NONE"; String surname = "NONE"; if (user.getFirstName() != null) { name = user.getFirstName(); } if (user.getLastName() != null) { surname = user.getLastName(); } Properties props = new Properties(); props.put("mail.smtp.host", server); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("skuska.api.3@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Your password to GPSWebApp server!!!"); //message.setText(userToken); message.setSubject("Your password to GPSWebApp server!!!"); message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ",</h1><br>your paassword to access GPSWebApp server is <b>" + user.getPass() + "</b>. <br>Please take note that you can change it in your settings. Have a pleasant day.</body></html>", "text/html"); Transport.send(message); FileLogger.getInstance() .createNewLog("Successfuly sent password recovery email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } }