List of usage examples for javax.mail.internet InternetAddress parse
public static InternetAddress[] parse(String addresslist) throws AddressException
From source file:org.olat.core.util.mail.manager.MailManagerImpl.java
private void appendRecipients(DBMailImpl mail, List<ContactList> ccLists, List<Address> toAddress, List<Address> ccAddress, boolean visible, boolean makeRealMail, MailerResult result) throws AddressException { //append cc/bcc recipients if (ccLists != null && !ccLists.isEmpty()) { for (ContactList contactList : ccLists) { if (makeRealMail && StringHelper.containsNonWhitespace(contactList.getName())) { Address[] groupAddress = InternetAddress.parse(contactList.getRFC2822Name() + ";"); if (groupAddress != null && groupAddress.length > 0) { for (Address groupAdd : groupAddress) { toAddress.add(groupAdd); }//from w w w .ja v a 2 s. c om } } for (String email : contactList.getStringEmails().values()) { DBMailRecipient recipient = new DBMailRecipient(); recipient.setEmailAddress(email); recipient.setGroup(contactList.getName()); recipient.setVisible(visible); recipient.setDeleted(Boolean.FALSE); recipient.setMarked(Boolean.FALSE); recipient.setRead(Boolean.FALSE); mail.getRecipients().add(recipient); if (makeRealMail) { createAddress(ccAddress, recipient, false, result, false); } } for (Identity identityEmail : contactList.getIdentiEmails().values()) { DBMailRecipient recipient = new DBMailRecipient(); if (identityEmail instanceof PersistentObject) { recipient.setRecipient(identityEmail); } else { recipient.setEmailAddress(identityEmail.getUser().getProperty(UserConstants.EMAIL, null)); } recipient.setGroup(contactList.getName()); recipient.setVisible(visible); recipient.setDeleted(Boolean.FALSE); recipient.setMarked(Boolean.FALSE); recipient.setRead(Boolean.FALSE); mail.getRecipients().add(recipient); if (makeRealMail) { createAddress(ccAddress, recipient, false, result, false); } } } } }
From source file:org.olat.core.util.mail.manager.MailManagerImpl.java
private MimeMessage createMimeMessage(Identity fromId, String mailFrom, Identity toId, String to, Identity ccId, List<ContactList> bccLists, MailContent content, MailerResult result) { try {/*from w w w . ja v a2 s . c o m*/ Address from; if (StringHelper.containsNonWhitespace(mailFrom)) { from = createFromAddress(mailFrom, result); } else if (fromId != null) { from = createFromAddress(fromId, result); } else { // fxdiff: change from/replyto, see FXOLAT-74 . if no from is set, use default sysadmin-address (adminemail). from = createAddress(WebappHelper.getMailConfig("mailReplyTo")); if (from == null) { logError("MailConfigError: mailReplyTo is not set", null); } } List<Address> toList = new ArrayList<Address>(); if (StringHelper.containsNonWhitespace(to)) { Address[] toAddresses = InternetAddress.parse(to); for (Address toAddress : toAddresses) { toList.add(toAddress); } } else if (toId != null) { Address toAddress = createAddress(toId, result, true); if (toAddress != null) { toList.add(toAddress); } } List<Address> ccList = new ArrayList<Address>(); if (ccId != null) { Address ccAddress = createAddress(ccId, result, true); if (ccAddress != null) { ccList.add(ccAddress); } } //add bcc contact lists List<Address> bccList = new ArrayList<Address>(); if (bccLists != null) { for (ContactList contactList : bccLists) { if (StringHelper.containsNonWhitespace(contactList.getName())) { Address[] groupNames = InternetAddress.parse(contactList.getRFC2822Name() + ";"); for (Address groupName : groupNames) { toList.add(groupName); } } Address[] members = contactList.getEmailsAsAddresses(); for (Address member : members) { bccList.add(member); } } } Address[] tos = toList.toArray(new Address[toList.size()]); Address[] ccs = ccList.toArray(new Address[ccList.size()]); Address[] bccs = bccList.toArray(new Address[bccList.size()]); return createMimeMessage(from, tos, ccs, bccs, content.getSubject(), content.getBody(), content.getAttachments(), result); } catch (MessagingException e) { logError("", e); return null; } }
From source file:com.cabserver.handler.Admin.java
@POST @Path("forgot-password") @Produces(MediaType.TEXT_HTML)/* w w w . j a v a 2 s . com*/ public Response forgotPassword(String jsonData) { // String data = ""; HashMap<String, String> responseMap = new HashMap<String, String>(); try { // log.info("forgotPassword before decoding = " + jsonData); jsonData = (URLDecoder.decode(jsonData, "UTF-8")); // log.info("forgotPassword >>" + jsonData); // jsonData = jsonData.split("=")[1]; if (jsonData.contains("=")) { jsonData = jsonData.split("=")[1]; // log.info("forgotPassword >> data=" + jsonData); } log.info("forgotPassword >> json data=" + jsonData); if (jsonData != null && jsonData.length() > 1) { // Gson gson = new Gson(); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(jsonData); // LoginInfo result = new LoginInfo(); String phone = (String) obj.get("phone"); // String password = (String) obj.get("password"); // log.info("phone =" + phone); // log.info("password =" + password); if (phone != null) { UserMaster um = DatabaseManager.getEmailIdByPhone(phone); if (um != null) { log.info("forgotPassword >> Email fetched by phone number. HTTP code is 200."); responseMap.put("code", "200"); responseMap.put("msg", "Password is sent to your registered E-Mail ID."); responseMap.put("phone", phone); // responseMap.put("password", um.getPassword()); // responseMap.put("mailid", um.getMailId()); try { if (Boolean.parseBoolean(ConfigDetails.constants.get("LOCAL_MAIL_SEND"))) { Message message = new MimeMessage(CacheBuilder.session); message.setFrom(new InternetAddress("VikingTaxee@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(um.getMailId())); message.setSubject("VikingTaxee Account Password Information"); message.setText("Dear Customer You password is : " + "\n\n " + um.getPassword()); Transport.send(message); log.info("forgotPassword >> Password is sent to your registered E-Mail ID."); } else { TravelMaster tm = new TravelMaster(); tm.setFromMailId("VikingTaxee@gmail.com"); tm.setToMailId(um.getMailId()); tm.setSubject("VikingTaxee Account Password Information"); tm.setMailText(um.getPassword()); tm.setMailType( Integer.parseInt(ConfigDetails.constants.get("MAIL_TYPE_FORGOT_PASSWORD"))); CacheBuilder.mailSendingDataMap.put((long) new Random().nextInt(100000), tm); } } catch (Exception e) { throw new RuntimeException(e); } } else { log.info("forgotPassword >> Password reset not done. Please call customer Care."); responseMap.put("code", ConfigDetails.constants.get("BOOKING_FAILED_CODE")); responseMap.put("msg", "Forgot password process can not be completed. Please call customer Care."); } } } } catch (Exception e) { e.printStackTrace(); } if (responseMap.size() < 1) { log.info("Login Error. HTTP bookingStatus code is " + ConfigDetails.constants.get("BOOKING_FAILED_CODE") + "."); responseMap.put("code", ConfigDetails.constants.get("BOOKING_FAILED_CODE")); responseMap.put("msg", "Server Error."); return Response.status(200).entity(jsonCreater(responseMap)).build(); } else { return Response.status(200).entity(jsonCreater(responseMap)).build(); } }
From source file:GUI.DashbordAdminFrame.java
private void btnEnvMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnvMailActionPerformed // TODO add your handling code here: String to = null;//from ww w . j a v a2 s.co m UserDao u = new UserDao(); List listeTo = new ArrayList(); listeTo = u.findAllEmail(); String from = "allfordealpi@gmail.com"; final String username = "allfordealpi@gmail.com"; final String password = "pidev2016"; 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); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); for (Object o : listeTo) { to = (String) o; System.out.println(to); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject(tfObjet.getText()); message.setText(taContenu.getText()); // Send message Transport.send(message); } System.out.println("Sent message successfully...."); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public boolean sendMail(HttpServletRequest request, String providerName, int providerID, String baseUrl) throws MessagingException { final String username = "registration@youtripper.com"; final String password = "Tripregister190515"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtpm.csloxinfo.com"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }//www. j av a2 s .co m }); //Create data for referral java.util.Date date = new java.util.Date(); String s = providerID + (new Timestamp(date.getTime()).toString()); MessageDigest m = null; try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ProviderServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } m.update(s.getBytes(), 0, s.length()); String md5 = (new BigInteger(1, m.digest()).toString(16)); String title = "You have an invitation from your friend."; String receiver = request.getParameter("email"); // StringBuilder messageContentHtml = new StringBuilder(); // messageContentHtml.append(request.getParameter("message") + "<br />\n"); // messageContentHtml.append("You can become a provider from here: " + baseUrl + "/Common/Provider/SignupReferral/" + md5); // String messageContent = messageContentHtml.toString(); String emailContent = " <div style='background: url(cid:bg_Icon) no-repeat;background-color:#ebebec;text-align: center;width:610px;height:365px'>" + " <p style='font-size:16px;padding-top: 45px; padding-bottom: 15px;'>Your friend <b>" + providerName + "</b> has invited you to complete purchase via</p>" + " <a href='http://youtripper.com/Common/Provider/SignupReferral/" + md5 + "' style='width: 160px;height: 50px;border-radius: 5px;border: 0;" + " background-color: #ff514e;font-size: 14px;font-weight: bolder;color: #fff;display: block;line-height: 50px;margin: 0 auto;text-decoration:none;' >Refferal Link</a>" + " <p style='font-size:16px;margin:30px;'><b>" + providerName + "</b> will get 25 credit</p>" + " <a href='http://youtripper.com' target='_blank'><img src='cid:gift_Icon' width='90' height='90'></a>" + " <a href='http://youtripper.com' target='_blank' style='font-size:10px;color:#939598;text-decoration:none'><p>from www.youtripper.com</p></a>" + " " + " " + " </div>"; String path = System.getProperty("catalina.base"); MimeBodyPart backgroundImage = new MimeBodyPart(); // attach the file to the message DataSource source = new FileDataSource(new File(path + "/webapps/Images/Email/backgroundImage.png")); backgroundImage.setDataHandler(new DataHandler(source)); backgroundImage.setFileName("backgroundImage.png"); backgroundImage.setDisposition(MimeBodyPart.INLINE); backgroundImage.setHeader("Content-ID", "<bg_Icon>"); // cid:image_cid MimeBodyPart giftImage = new MimeBodyPart(); // attach the file to the message source = new FileDataSource(new File(path + "/webapps/Images/Email/emailGift.png")); giftImage.setDataHandler(new DataHandler(source)); giftImage.setFileName("emailGift.png"); giftImage.setDisposition(MimeBodyPart.INLINE); giftImage.setHeader("Content-ID", "<gift_Icon>"); // cid:image_cid MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(emailContent, "US-ASCII", "html"); Multipart mp = new MimeMultipart("related"); mp.addBodyPart(mbp1); mp.addBodyPart(backgroundImage); mp.addBodyPart(giftImage); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("registration@youtripper.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver)); message.setSubject(title); message.setContent(mp); message.saveChanges(); Transport.send(message); ReferralDTO referral = new ReferralDTO(providerID, receiver, String.valueOf(System.currentTimeMillis()), md5, 0); referralDAO.insertNewReferral(referral); return true; }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public boolean sendEmailReferral(String data, int providerID, String baseUrl) throws MessagingException { final String username = "registration@youtripper.com"; final String password = "Tripregister190515"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "mail.youtripper.com"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*from w ww. jav a2s . co m*/ }); String title = "You have an invitation from your friend."; JsonObject jsonObject = gson.fromJson(data, JsonObject.class); String content = jsonObject.get("content").getAsString(); JsonArray sportsArray = jsonObject.get("emails").getAsJsonArray(); ArrayList<String> listEmail = new ArrayList<>(); if (sportsArray != null) { for (int i = 0; i < sportsArray.size(); i++) { listEmail.add(sportsArray.get(i).getAsString()); } } String path = System.getProperty("catalina.base"); MimeBodyPart backgroundImage = new MimeBodyPart(); // attach the file to the message DataSource source = new FileDataSource(new File(path + "/webapps/Images/Email/backgroundImage.png")); backgroundImage.setDataHandler(new DataHandler(source)); backgroundImage.setFileName("backgroundImage.png"); backgroundImage.setDisposition(MimeBodyPart.INLINE); backgroundImage.setHeader("Content-ID", "<bg_Icon>"); // cid:image_cid MimeBodyPart giftImage = new MimeBodyPart(); // attach the file to the message source = new FileDataSource(new File(path + "/webapps/Images/Email/emailGift.png")); giftImage.setDataHandler(new DataHandler(source)); giftImage.setFileName("emailGift.png"); giftImage.setDisposition(MimeBodyPart.INLINE); giftImage.setHeader("Content-ID", "<gift_Icon>"); // cid:image_cid MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(content, "US-ASCII", "html"); Multipart mp = new MimeMultipart("related"); mp.addBodyPart(mbp1); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("registration@youtripper.com")); String addresses = ""; for (int i = 0; i < listEmail.size(); i++) { if (i < listEmail.size() - 1) { addresses = addresses + listEmail.get(i) + ","; } else { addresses = addresses + listEmail.get(i); } } message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addresses)); message.setSubject(title); message.setContent(mp); message.saveChanges(); try { Transport.send(message); } catch (Exception e) { e.printStackTrace(); } System.out.println("sent"); return true; }
From source file:FirstStatMain.java
private void btnsendemailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsendemailActionPerformed final String senderemail = txtEmailfrom.getText(); final String sendPass = txtPassword.getText(); String send_to = txtEmailto.getText(); String email_sub = txtemailsbj.getText(); String email_body = tABody.getText(); Properties prop = new Properties(); prop.put("mail.smtp.host", "smtp.gmail.com"); prop.put("mail.smtp.socketFactory.port", "465"); prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); prop.put("mail.smtp.auth", "true"); prop.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() { @Override//from www . j a va 2 s. c om protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(senderemail, sendPass); } }); try { /* Message Header*/ Message message = new MimeMessage(session); message.setFrom(new InternetAddress(senderemail)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(send_to)); message.setSubject(email_sub); /*setting text message*/ MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(email_body); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); /*attaching file*/ messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(file_path); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(txtattachmentname.getText()); multipart.addBodyPart(messageBodyPart); message.setContent(multipart); Transport.send(message); JOptionPane.showMessageDialog(rootPane, "Message sent"); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, e); } }
From source file:net.spfbl.http.ServerHTTP.java
private static boolean enviarDesbloqueioDNSBL(Locale locale, String url, String ip, String email) throws MessagingException { if (url == null) { return false; } else if (!Core.hasOutputSMTP()) { return false; } else if (!Core.hasAdminEmail()) { return false; } else if (!Domain.isEmail(email)) { return false; } else if (NoReply.contains(email, true)) { return false; } else {/*from w w w .ja va 2s . co m*/ try { Server.logDebug("sending unblock by e-mail."); User user = User.get(email); InternetAddress[] recipients; if (user == null) { recipients = InternetAddress.parse(email); } else { recipients = new InternetAddress[1]; recipients[0] = user.getInternetAddress(); } Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props); MimeMessage message = new MimeMessage(session); message.setHeader("Date", Core.getEmailDate()); message.setFrom(Core.getAdminInternetAddress()); message.addRecipients(Message.RecipientType.TO, recipients); String subject; if (locale.getLanguage().toLowerCase().equals("pt")) { subject = "Chave de desbloqueio SPFBL"; } else { subject = "Unblocking key SPFBL"; } message.setSubject(subject); // Corpo da mensagem. StringBuilder builder = new StringBuilder(); builder.append("<!DOCTYPE html>\n"); builder.append("<html lang=\""); builder.append(locale.getLanguage()); builder.append("\">\n"); builder.append(" <head>\n"); builder.append(" <meta charset=\"UTF-8\">\n"); builder.append(" <title>"); builder.append(subject); builder.append("</title>\n"); loadStyleCSS(builder); if (locale.getLanguage().toLowerCase().equals("pt")) { buildConfirmAction(builder, "Desbloquear IP", url, "Confirme o desbloqueio para o IP " + ip + " na DNSBL", "SPFBL.net", "http://spfbl.net/"); } else { buildConfirmAction(builder, "Delist IP", url, "Confirm the delist of IP " + ip + " at DNSBL", "SPFBL.net", "http://spfbl.net/en/"); } builder.append(" </head>\n"); builder.append(" <body>\n"); builder.append(" <div id=\"container\">\n"); builder.append(" <div id=\"divlogo\">\n"); builder.append(" <img src=\"cid:logo\">\n"); builder.append(" </div>\n"); if (locale.getLanguage().toLowerCase().equals("pt")) { buildMessage(builder, "Desbloqueio do IP " + ip + " na DNSBL"); buildText(builder, "Se voc o administrador deste IP, e fez esta solicitao, acesse esta URL e resolva o reCAPTCHA para finalizar o procedimento:"); } else { buildMessage(builder, "Unblock of IP " + ip + " at DNSBL"); buildText(builder, "If you are the administrator of this IP and made this request, go to this URL and solve the reCAPTCHA to finish the procedure:"); } buildText(builder, "<a href=\"" + url + "\">" + url + "</a>"); buildFooter(builder, locale); builder.append(" </div>\n"); builder.append(" </body>\n"); builder.append("</html>\n"); // Making HTML part. MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(builder.toString(), "text/html;charset=UTF-8"); // Making logo part. MimeBodyPart logoPart = new MimeBodyPart(); File logoFile = getWebFile("logo.png"); logoPart.attachFile(logoFile); logoPart.setContentID("<logo>"); logoPart.addHeader("Content-Type", "image/png"); logoPart.setDisposition(MimeBodyPart.INLINE); // Join both parts. MimeMultipart content = new MimeMultipart("related"); content.addBodyPart(htmlPart); content.addBodyPart(logoPart); // Set multiplart content. message.setContent(content); message.saveChanges(); // Enviar mensagem. return Core.sendMessage(message, 30000); } catch (MailConnectException ex) { throw ex; } catch (SendFailedException ex) { throw ex; } catch (MessagingException ex) { throw ex; } catch (Exception ex) { Server.logError(ex); return false; } } }
From source file:net.spfbl.http.ServerHTTP.java
private static boolean enviarDesbloqueio(String url, String remetente, String destinatario) throws SendFailedException, MessagingException { if (url == null) { return false; } else if (!Core.hasOutputSMTP()) { return false; } else if (!Domain.isEmail(destinatario)) { return false; } else if (NoReply.contains(destinatario, true)) { return false; } else {/*from w w w. j ava 2s . com*/ try { Server.logDebug("sending unblock by e-mail."); Locale locale = User.getLocale(destinatario); InternetAddress[] recipients = InternetAddress.parse(destinatario); Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props); MimeMessage message = new MimeMessage(session); message.setHeader("Date", Core.getEmailDate()); message.setFrom(Core.getAdminEmail()); message.setReplyTo(InternetAddress.parse(remetente)); message.addRecipients(Message.RecipientType.TO, recipients); String subject; if (locale.getLanguage().toLowerCase().equals("pt")) { subject = "Solicitao de envio SPFBL"; } else { subject = "SPFBL send request"; } message.setSubject(subject); // Corpo da mensagem. StringBuilder builder = new StringBuilder(); builder.append("<!DOCTYPE html>\n"); builder.append("<html lang=\""); builder.append(locale.getLanguage()); builder.append("\">\n"); builder.append(" <head>\n"); builder.append(" <meta charset=\"UTF-8\">\n"); builder.append(" <title>"); builder.append(subject); builder.append("</title>\n"); loadStyleCSS(builder); builder.append(" </head>\n"); builder.append(" <body>\n"); builder.append(" <div id=\"container\">\n"); builder.append(" <div id=\"divlogo\">\n"); builder.append(" <img src=\"cid:logo\">\n"); builder.append(" </div>\n"); buildMessage(builder, subject); if (locale.getLanguage().toLowerCase().equals("pt")) { buildText(builder, "Este e-mail foi gerado pois nosso servidor recusou uma ou mais mensagens do remetente " + remetente + " e o mesmo requisitou que seja feita a liberao para que novos e-mails possam ser entregues a voc."); buildText(builder, "Se voc deseja receber e-mails de " + remetente + ", acesse o endereo abaixo e para iniciar o processo de liberao:"); } else { buildText(builder, "This email was generated because our server has refused one or more messages from the sender " + remetente + " and the same sender has requested that the release be made for new emails can be delivered to you."); buildText(builder, "If you wish to receive emails from " + remetente + ", access the address below and to start the release process:"); } buildText(builder, "<a href=\"" + url + "\">" + url + "</a>"); buildFooter(builder, locale); builder.append(" </div>\n"); builder.append(" </body>\n"); builder.append("</html>\n"); // Making HTML part. MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(builder.toString(), "text/html;charset=UTF-8"); // Making logo part. MimeBodyPart logoPart = new MimeBodyPart(); File logoFile = getWebFile("logo.png"); logoPart.attachFile(logoFile); logoPart.setContentID("<logo>"); logoPart.addHeader("Content-Type", "image/png"); logoPart.setDisposition(MimeBodyPart.INLINE); // Join both parts. MimeMultipart content = new MimeMultipart("related"); content.addBodyPart(htmlPart); content.addBodyPart(logoPart); // Set multiplart content. message.setContent(content); message.saveChanges(); // Enviar mensagem. return Core.sendMessage(message, 5000); } catch (MailConnectException ex) { throw ex; } catch (SendFailedException ex) { throw ex; } catch (MessagingException ex) { throw ex; } catch (Exception ex) { Server.logError(ex); return false; } } }
From source file:net.spfbl.http.ServerHTTP.java
private static boolean enviarConfirmacaoDesbloqueio(String destinatario, String remetente, Locale locale) { if (Core.hasOutputSMTP() && Core.hasAdminEmail() && Domain.isEmail(remetente) && !NoReply.contains(remetente, true)) { try {//from w ww . ja v a2 s. c o m Server.logDebug("sending unblock confirmation by e-mail."); InternetAddress[] recipients = InternetAddress.parse(remetente); Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props); MimeMessage message = new MimeMessage(session); message.setHeader("Date", Core.getEmailDate()); message.setFrom(Core.getAdminEmail()); message.setReplyTo(InternetAddress.parse(destinatario)); message.addRecipients(Message.RecipientType.TO, recipients); String subject; if (locale.getLanguage().toLowerCase().equals("pt")) { subject = "Confirmao de desbloqueio SPFBL"; } else { subject = "SPFBL unblocking confirmation"; } message.setSubject(subject); // Corpo da mensagem. StringBuilder builder = new StringBuilder(); builder.append("<!DOCTYPE html>\n"); builder.append("<html lang=\""); builder.append(locale.getLanguage()); builder.append("\">\n"); builder.append(" <head>\n"); builder.append(" <meta charset=\"UTF-8\">\n"); builder.append(" <title>"); builder.append(subject); builder.append("</title>\n"); loadStyleCSS(builder); builder.append(" </head>\n"); builder.append(" <body>\n"); builder.append(" <div id=\"container\">\n"); builder.append(" <div id=\"divlogo\">\n"); builder.append(" <img src=\"cid:logo\">\n"); builder.append(" </div>\n"); buildMessage(builder, subject); if (locale.getLanguage().toLowerCase().equals("pt")) { buildText(builder, "O destinatrio '" + destinatario + "' acabou de liberar o recebimento de suas mensagens."); buildText(builder, "Por favor, envie novamente a mensagem anterior."); } else { buildText(builder, "The recipient '" + destinatario + "' just released the receipt of your message."); buildText(builder, "Please send the previous message again."); } buildFooter(builder, locale); builder.append(" </div>\n"); builder.append(" </body>\n"); builder.append("</html>\n"); // Making HTML part. MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(builder.toString(), "text/html;charset=UTF-8"); // Making logo part. MimeBodyPart logoPart = new MimeBodyPart(); File logoFile = getWebFile("logo.png"); logoPart.attachFile(logoFile); logoPart.setContentID("<logo>"); logoPart.addHeader("Content-Type", "image/png"); logoPart.setDisposition(MimeBodyPart.INLINE); // Join both parts. MimeMultipart content = new MimeMultipart("related"); content.addBodyPart(htmlPart); content.addBodyPart(logoPart); // Set multiplart content. message.setContent(content); message.saveChanges(); // Enviar mensagem. return Core.sendMessage(message, 5000); } catch (MessagingException ex) { return false; } catch (Exception ex) { Server.logError(ex); return false; } } else { return false; } }