public Email parse(final Map<String, String> keyVals) { if (_parsed) { return _email; } _email = new Email(); if (null == keyVals) { return _email; } keyVals.putAll(parseScript(keyVals)); Iterator<String> i = keyVals.keySet().iterator(); while (i.hasNext()) { String key = i.next(); String token = "@" + key + "@"; String val = keyVals.get(key); val = Matcher.quoteReplacement(val); _addressee = _addressee.replaceAll(token, val); _subject = _subject.replaceAll(token, val); _template = _template.replaceAll(token, val); } _email.setSubject(_subject); _email.setTo(_addressee.split(",")); _email.setBody(_template); _parsed = true; return _email; }
@Override public void serializeContent(XmlSerializer serializer) throws IOException { if (isEmpty()) return; SerializerUtils.addTextTag(serializer, VCardProperty.FN.toString(), getFormattedName()); serializer.startTag(null, N_NAME); for (Entry<NameProperty, String> entry : name.entrySet()) SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue()); serializer.endTag(null, N_NAME); for (Entry<VCardProperty, String> entry : properties.entrySet()) if (entry.getKey() != VCardProperty.FN) SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue()); for (Photo photo : photos) photo.serialize(serializer); for (Address address : addresses) address.serialize(serializer); for (Label label : labels) label.serialize(serializer); for (Telephone telephone : telephones) telephone.serialize(serializer); for (Email email : emails) email.serialize(serializer); for (Logo logo : logos) logo.serialize(serializer); for (Sound sound : sounds) sound.serialize(serializer); for (Geo geo : geos) geo.serialize(serializer); for (Organization organization : organizations) organization.serialize(serializer); if (!categories.isEmpty()) { serializer.startTag(null, CATEGORIES_NAME); for (String keyword : categories) SerializerUtils.addTextTag(serializer, KEYWORD_NAME, keyword); serializer.endTag(null, CATEGORIES_NAME); } if (classification != null) SerializerUtils.addTextTag(serializer, CLASS_NAME, classification.toString()); for (Key key : keys) key.serialize(serializer); }
public final Email buildEmail() { final Email email = new Email(); email.setAttachments(getAttachments()); email.setContent(getContent()); email.setSubject(subject); email.setTo(getTo()); return email; }
private void assertThatOnlyNewEmailAddressIsPrimary() { for (Email email : returnUser.getEmails()) { if (email.getValue().equals("*****@*****.**")) { assertThat(email.isPrimary(), is(true)); } else { assertThat(email.isPrimary(), is(false)); } } }
private boolean isValuePartOfEmailList(List<Email> list, String value) { if (list != null) { for (Email actAttribute : list) { if (actAttribute.getValue().equals(value)) { return true; } } } return false; }
public void sendMail(Email email) throws MessagingException { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, "UTF-8"); messageHelper.setSubject(email.getSubject()); messageHelper.setTo(email.getReceiver()); messageHelper.setFrom(sender); messageHelper.setText(email.getContent(), true); mailSender.send(message); }
private MimeMessage getMessage(Email email, Session session) throws AddressException, MessagingException { MimeMessage result = new MimeMessage(session); result.setFrom(new InternetAddress(email.getFrom())); result.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email.getTo())); result.setSubject(email.getSubject()); if (email.getAttachment() != null) { // message body part MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(email.getMsg()); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource attachmentSource = new ByteArrayDataSource( email.getAttachment().getContent(), email.getAttachment().getAttachmentType()); attachmentPart.setDataHandler(new DataHandler(attachmentSource)); attachmentPart.setFileName(email.getAttachment().getFileName()); multipart.addBodyPart(attachmentPart); result.setContent(multipart); } else { result.setContent(email.getMsg(), "text/plain"); } return result; }
public static List<String> getEmailsFromPersonName(String personName) throws NotExistsPersonException { Person person = getPersonFromIdentifier(personName); List<Email> emails = person.getEmails(); List<String> result = new ArrayList<String>(); for (Email email : emails) { result.add(email.getEmail()); } return result; }
@Bean protected AsynchronousEventTaskJobFactory asynchronousEventTaskJobFactory() { return new AsynchronousEventTaskJobFactory( // data.systemDataView(), // email.emailAccountFacade(), // email.emailTemplateLogic(), // taskStore(), // defaultLogicAndStoreConverter(), // emailTemplateSenderFactory() // ); }
@Bean protected ConnectorTaskJobFactory connectorTaskJobFactory() { return new ConnectorTaskJobFactory( // data.systemDataView(), // other.dataSourceHelper(), // defaultAttributeValueAdapter(), // email.emailAccountFacade(), // email.emailTemplateLogic(), // emailTemplateSenderFactory() // ); }
private Message composeMessage(Email email, String contentType) throws EmailCompositionException { Message message = new MimeMessage(session); try { message.setFrom(createInternetAddress(email.getFrom())); setRecipients(email, message); message.setSubject(email.getSubject()); message.setContent(email.getMessageText(), contentType); } catch (Exception e) { throw new EmailCompositionException(e); } return message; }
private void saveToCache(MimeMessage[] messages) { for (int i = 0; i < messages.length; i++) { Email email = new Email(); try { email.setMessageID(messages[i].getMessageID()); HashSet<String> from = new HashSet<String>(); if (messages[i].getFrom() != null) { from = getEmailAdress(messages[i].getFrom()); } email.setFrom(from); HashSet<Email> replies = new HashSet<Email>(); if (messages[i].getHeader("In-Reply-To") != null) { String inReplyTo = extractReplyID(messages[i].getHeader("In-Reply-To")[0]); email.setInReplyTo(inReplyTo); replies.add(emailData.get(inReplyTo)); } if (messages[i].getHeader("References") != null) { HashSet<Email> referenceList = getEmailAdress(messages[i].getHeader("References")[0]); email.setReferences(referenceList); replies.addAll(referenceList); } email.setReplies(replies); if (messages[i].getAllRecipients() != null) { email.setAllRecipients(getEmailAdress(messages[i].getAllRecipients())); } email.setSubject(messages[i].getSubject()); // email.put("content", getText(messages[i])); email.setSentDate(messages[i].getSentDate()); emailData.put(email.getMessageID(), email); // recursiveProcessReplies(email); emailCount++; } catch (MessagingException e) { emailLevelErrors++; // System.out.println("MessagingException on saveToDB: getContents: " + e.getMessage()); } } }
/** * Get the template for an email message. The message is suitable for inserting values using * <code>java.text.MessageFormat</code>. * * @param emailFile full name for the email template, for example * "/dspace/config/emails/register". * @return the email object, with the content and subject filled out from the template * @throws IOException if the template couldn't be found, or there was some other error reading * the template */ public static Email getEmail(String emailFile) throws IOException { String charset = null; String subject = ""; StringBuffer contentBuffer = new StringBuffer(); // Read in template BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(emailFile)); boolean more = true; while (more) { String line = reader.readLine(); if (line == null) { more = false; } else if (line.toLowerCase().startsWith("subject:")) { // Extract the first subject line - everything to the right // of the colon, trimmed of whitespace subject = line.substring(8).trim(); // 20110611 by Pudding Chen Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = df.format(date); subject = subject + " (" + time + ")"; } else if (line.toLowerCase().startsWith("charset:")) { // Extract the character set from the email charset = line.substring(8).trim(); } else if (!line.startsWith("#")) { // Add non-comment lines to the content contentBuffer.append(line); contentBuffer.append("\n"); } } } finally { if (reader != null) { reader.close(); } } // Create an email Email email = new Email(); email.setSubject(subject); email.setContent(contentBuffer.toString()); if (charset != null) email.setCharset(charset); return email; }
public void printContents() { int i = 0; for (Email e : emails) { System.out.println( i + "--> \nTo: " + e.getTo() + "\nSubject: " + e.getSubject() + "\nDate: " + e.getTimestamp().getTime()); i++; } }
protected void notifyOfReject( Context context, BasicWorkflowItem workflowItem, EPerson e, String reason) { try { // Get the item title String title = getItemTitle(workflowItem); // Get the collection Collection coll = workflowItem.getCollection(); // Get rejector's name String rejector = getEPersonName(e); Locale supportedLocale = I18nUtil.getEPersonLocale(e); Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_reject")); email.addRecipient(workflowItem.getSubmitter().getEmail()); email.addArgument(title); email.addArgument(coll.getName()); email.addArgument(rejector); email.addArgument(reason); email.addArgument(getMyDSpaceLink()); email.send(); } catch (RuntimeException re) { // log this email error log.warn( LogManager.getHeader( context, "notify_of_reject", "cannot email user eperson_id=" + e.getID() + " eperson_email=" + e.getEmail() + " workflow_item_id=" + workflowItem.getID() + ": " + re.getMessage())); throw re; } catch (Exception ex) { // log this email error log.warn( LogManager.getHeader( context, "notify_of_reject", "cannot email user eperson_id=" + e.getID() + " eperson_email=" + e.getEmail() + " workflow_item_id=" + workflowItem.getID() + ": " + ex.getMessage())); } }
@Override @Transactional public void sendAdminChangePasswordNotification(Map<String, Object> obj) { try { this.simpleMailMessage.setTo(obj.get("emailId").toString()); Email mail = this.getMailTemplate(CHANGE_PASSWORD_BY_ADMIN); this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; String text1 = String.format(mail.getValue(), obj.get("empname"), obj.get("newpassword")); this.sendMail(text, text1, null); } catch (Exception ex) { ex.printStackTrace(); logger.error("Exception in Method:sendAdminChangePasswordNotification", ex); } }
@Override public void send(Email email) { Message message = createMessage(); try { message.setSubject(email.getSubject()); message.setContent(email.getContent(), "text/html;charset=utf-8"); message.setRecipients(Message.RecipientType.TO, toAddress(email.getTo())); message.setRecipients(Message.RecipientType.CC, toAddress(email.getCc())); Transport.send(message); } catch (MessagingException e) { logger.error("InstallUtils executeSQL erro", e); } }
public static boolean sendEmail(String emailStr, String topic, String body) { Email email = Email.create(emailStr); if (!emailValidator.validate(email)) { return false; } return emailService.send(email, topic, body); }
@Override public void sendTsApproveNotificationToAll(String[] obj, Calendar cal) { try { if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { this.simpleMailMessage.setTo(obj); Email mail = null; mail = this.getMailTemplate(TS_APPROVE_ALERT_MGR); this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; String text1 = String.format(mail.getValue()); this.sendMail(text, text1, null); } } catch (Exception ex) { logger.error("Exception in Method:sendTsApproveNotificationToAll", ex); } }
@Override protected void onPostExecute(String result) { // Log.e("Joseph", result); Gson gson = new Gson(); Authorisation auth = gson.fromJson(result, Authorisation.class); String error = auth.getError(); if (error.equals("false")) { // User has logged in successfully and api key has been issued // Send data to FragmentActivity by hooking into UI event APIKEY = auth.getApikey(); if (mListener != null) { String[] authDetails = {auth.getName(), auth.getEmail(), auth.getApikey()}; mListener.onFragmentInteraction(authDetails); Toast.makeText(getActivity(), auth.getMessage(), Toast.LENGTH_SHORT).show(); // Update the list in the Drawer so that it can show logout CloseFragment(); } } else { // Login failed because error was returned from service registerFailed.setText(auth.getMessage()); registerFailed.setTextColor(Color.RED); Name.setText(""); Email.setText(""); Password.setText(""); ConfirmPassword.setText(""); Name.requestFocus(); } }
@Bean protected ReadEmailTaskJobFactory readEmailTaskJobFactory() { return new ReadEmailTaskJobFactory( // email.emailAccountFacade(), // email.emailServiceFactory(), // email.subjectHandler(), // email.emailStore(), // workflow .systemWorkflowLogicBuilder() // .build(), // dms.defaultDmsLogic(), // data.systemDataView(), // email.emailTemplateLogic(), // template.databaseTemplateEngine(), // emailTemplateSenderFactory() // ); }
@Override @Transactional public void sendTSSubmitNotificationToMgr(Map<String, Object> obj, int status) { try { this.simpleMailMessage.setTo(obj.get("toemailid").toString()); this.simpleMailMessage.setCc(obj.get("ccemailid").toString()); Email mail = new Email(); String text1 = new String(); if (status == 4) { mail = this.getMailTemplate(TIMESHEET_SUBMIT_NOTIFICATION); text1 = String.format( mail.getValue(), obj.get("toname"), obj.get("ccname"), obj.get("dateweek"), obj.get("status")); } if (status == 6) { mail = this.getMailTemplate(TIMESHEET_ARROVAL_NOTIFICATION); text1 = String.format( mail.getValue(), obj.get("ccname"), obj.get("toname"), obj.get("dateweek"), obj.get("status")); } if (status == 5) { mail = this.getMailTemplate(TIMESHEET_REJECTED_NOTIFICATION); text1 = String.format( mail.getValue(), obj.get("ccname"), obj.get("toname"), obj.get("dateweek"), obj.get("status")); } this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; this.sendMail(text, text1, null); } catch (Exception ex) { ex.printStackTrace(); logger.error("Exception in Method:sendTSSubmitNotificationToMgr", ex); } }
private void setRecipients(Email email, Message message) { for (Recipient recipient : email.getRecipients()) { try { message.addRecipient(recipient.getType(), createInternetAddress(recipient)); } catch (Exception e) { e.printStackTrace(); } } }
@Override @Transactional public void sendCreateUserNotification(Map<String, Object> user) { try { this.simpleMailMessage.setTo(user.get("emailId").toString()); Email mail = this.getMailTemplate(CREATE_USER_TPL); this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; String text1 = String.format( mail.getValue(), user.get("fname") + " , " + user.get("lname"), user.get("username"), user.get("password_copy")); this.sendMail(text, text1, null); } catch (Exception ex) { logger.error("Exception in Method:sendCreateUserNotification", ex); } }
/** Send the email. */ public void sendEmail(Email outgoing) { LOG.trace("ENTER"); outgoing.setStatus(Email.STATUS_OUTBOX); outbox.add(outgoing); if (emailListener != null) { emailListener.outgoingEmailEvent(null, outgoing); } LOG.debug("E-mail added to outbox. Size is [" + outbox.size() + "]"); LOG.trace("EXIT"); }
@Override public void sendTSSubmissionNotificationToAll(String[] obj, Calendar cal) { try { if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { this.simpleMailMessage.setTo(obj); Email mail = null; if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) mail = this.getMailTemplate(TS_SUB_NOTIC_TO_DEFALUTER); else mail = this.getMailTemplate(TS_SUB_NOTIC_TO_ALL); this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; String text1 = String.format(mail.getValue()); this.sendMail(text, text1, null); } } catch (Exception ex) { logger.error("Exception in Method:sendTSSubmissionNotificationToAll", ex); } }
@Override public void alertUsersOnTaskActivation( Context c, XmlWorkflowItem wfi, String emailTemplate, List<EPerson> epa, String... arguments) throws IOException, SQLException, MessagingException { if (noEMail.containsKey(wfi.getItem().getID())) { // suppress email, and delete key noEMail.remove(wfi.getItem().getID()); } else { Email mail = Email.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), emailTemplate)); for (String argument : arguments) { mail.addArgument(argument); } for (EPerson anEpa : epa) { mail.addRecipient(anEpa.getEmail()); } mail.send(); } }
@Bean protected ObserverFactory observerFactory() { return new DefaultObserverFactory( // userStore, // api.systemFluentApi(), // workflow.systemWorkflowLogicBuilder().build(), // email.emailAccountFacade(), // email.emailTemplateLogic(), // data.systemDataView(), // new Supplier<CMDataView>() { @Override public CMDataView get() { return user.userDataView(); } }, // emailTemplateSenderFactory() // ); }
@Override public void sendNewBugNotification(Map<String, Object> issue) { try { String[] str = new String[2]; str[0] = "*****@*****.**"; str[1] = "*****@*****.**"; this.simpleMailMessage.setTo(str); this.simpleMailMessage.setCc(issue.get("emailId").toString()); Email mail = this.getMailTemplate(ADD_BUG_NOTIFICATION); this.simpleMailMessage.setSubject(mail.getSubject()); String text = "Text mode not supported, please turn on Standard mode."; String text1 = String.format( mail.getValue(), issue.get("fname"), issue.get("title"), issue.get("createdOn")); this.sendMail(text, text1, null); } catch (Exception ex) { logger.error("Exception in Method:sendCreateUserNotification", ex); } }
/** @参数名:@param subject 邮件主题 @参数名:@param content 邮件主题内容 @参数名:@param to 收件人Email地址 */ public static void send(String subject, String content, String to) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-smtp-mail.xml"); Email mm = (Email) context.getBean("simpleMail"); try { LOGGER.info( "Params : createTime = [" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()) + "] , subject = [" + subject + "] , content = [" + content + "] , to = [" + to + "]"); mm.sendMail(subject, content, to); context.close(); } catch (MessagingException e) { LOGGER.info("context", e); } }