List of usage examples for javax.mail.internet InternetAddress getAddress
public String getAddress()
From source file:mitm.application.djigzo.james.matchers.SenderHeaderTrigger.java
private String getTriggerAction(Mail mail) throws DatabaseException { String trigger = null;/*from w ww.j a va2s .c o m*/ try { InternetAddress originator = messageOriginatorIdentifier.getOriginator(mail); if (originator != null) { String userEmail = originator.getAddress(); userEmail = EmailAddressUtils.canonicalizeAndValidate(userEmail, false); User user = userWorkflow.getUser(userEmail, UserWorkflow.GetUserMode.CREATE_IF_NOT_EXIST); UserProperties userProperties = user.getUserPreferences().getProperties(); trigger = userProperties.getProperty(property, false); } return trigger; } catch (MessagingException e) { throw new DatabaseException(e); } catch (HierarchicalPropertiesException e) { throw new DatabaseException(e); } }
From source file:immf.SendMailPicker.java
private void errorNotify(String error, SenderMail errMail) { ForwardEmail mail = new ForwardEmail(conf); mail.setCharset(this.conf.getMailEncode()); // SMTP Server mail.setHostName(conf.getSmtpServer()); mail.setSmtpPort(conf.getSmtpPort()); mail.setSocketConnectionTimeout(conf.getSmtpConnectTimeoutSec() * 1000); mail.setSocketTimeout(conf.getSmtpTimeoutSec() * 1000); mail.setTLS(conf.isSmtpTls());/*from w ww . ja va 2 s. c o m*/ if (!StringUtils.isBlank(conf.getSmtpUser())) { mail.setAuthentication(conf.getSmtpUser(), conf.getSmtpPasswd()); } if (!StringUtils.isBlank(conf.getPopServer()) && !StringUtils.isBlank(conf.getPopUser())) { // POP before SMTP mail.setPopBeforeSmtp(true, conf.getPopServer(), conf.getPopUser(), conf.getPopPasswd()); } try { mail.setFrom(this.conf.getSmtpMailAddress(), "imoten"); mail.addTo(this.conf.getSmtpMailAddress()); if (!this.conf.getForwardTo().isEmpty()) { mail.addHeader("Resent-To", StringUtils.join(this.conf.getForwardTo(), ",")); } if (!this.conf.getForwardCc().isEmpty()) { mail.addHeader("Resent-Cc", StringUtils.join(this.conf.getForwardCc(), ",")); } if (!this.conf.getForwardBcc().isEmpty()) { mail.addHeader("Resent-Bcc", StringUtils.join(this.conf.getForwardBcc(), ",")); } mail.setSubject("?"); String body = "imoten???????\r\n\r\n"; body += "?\r\n"; body += error; body += "\r\n\r\n"; body += "?\r\n"; if (errMail == null) { body += "null"; } else { // To List<InternetAddress> list = errMail.getTo(); List<String> addrList = new ArrayList<String>(); for (InternetAddress addr : list) { addrList.add(addr.getAddress()); } String errTo = StringUtils.join(addrList, ","); if (!errTo.isEmpty()) { body += "To: " + errTo + "\r\n"; } // Cc list = errMail.getCc(); addrList = new ArrayList<String>(); for (InternetAddress addr : list) { addrList.add(addr.getAddress()); } String errCc = StringUtils.join(addrList, ","); if (!errCc.isEmpty()) { body += "Cc: " + errCc + "\r\n"; } // Bcc list = errMail.getBcc(); addrList = new ArrayList<String>(); for (InternetAddress addr : list) { addrList.add(addr.getAddress()); } String errBcc = StringUtils.join(addrList, ","); if (!errBcc.isEmpty()) { body += "Bcc: " + errBcc + "\r\n"; } // Subject String errSubject = ""; errSubject = errMail.getSubject(); body += "Subject: " + errSubject + "\r\n"; body += "\r\n"; // Body String errBody = ""; errBody = errMail.getPlainBody(); if (errBody.length() > 100) { body += errBody.substring(0, 100); body += "..."; } else { body += errBody; } } mail.setMsg(body); mail.send(); log.info(""); server.notify("?\n" + error); } catch (EmailException e) { log.warn("", e); } }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryItemEntity.java
@Override public void setRecipients(Collection<InternetAddress> recipients) throws AddressException { this.recipients.clear(); if (recipients != null) { for (InternetAddress recipient : recipients) { this.recipients.add(recipient.getAddress()); }/*from w w w. j a v a 2 s .c om*/ } }
From source file:com.thruzero.domain.service.impl.SimpleMailService.java
/** * @param filters set of recipients that can receive notifications * @return true if the recipient can receive an email *///from ww w . ja v a 2 s. com @Override public boolean isSendMailAllowed(Set<String> filters, InternetAddress to) { return filters == null || filters.isEmpty() || filters.contains(to.getAddress().toLowerCase()); }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryItemEntity.java
@Override public void setSender(InternetAddress sender) throws AddressException { this.sender = sender != null ? sender.getAddress() : null; }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryItemEntity.java
@Override public void setOriginator(InternetAddress originator) throws AddressException { this.originator = originator != null ? originator.getAddress() : null; }
From source file:com.szmslab.quickjavamail.receive.MessageLoader.java
/** * InternetAddress??MailAddress??????/* w ww. j a v a2 s. c om*/ * * @param addresses * InternetAddress?? * @return MailAddress? */ private List<MailAddress> toMailAddressList(InternetAddress[] addresses) { List<MailAddress> list = new ArrayList<MailAddress>(); if (addresses != null) { for (InternetAddress address : addresses) { list.add(new MailAddress(address.getAddress(), address.getPersonal())); } } return list; }
From source file:nl.surfnet.coin.teams.control.AddMemberController.java
private void doInviteMembers(final InternetAddress[] emails, final InvitationForm form, final Locale locale) { // Send the invitation String teamId = form.getTeamId(); Team team = controllerUtil.getTeamById(teamId); String inviterPersonId = form.getInviter().getId(); Object[] messageValuesSubject = { team.getName() }; String subject = messageSource.getMessage(INVITE_SEND_INVITE_SUBJECT, messageValuesSubject, locale); // Add an activity for every member that has been invited to the team. for (InternetAddress email : emails) { String emailAddress = email.getAddress(); Invitation invitation = teamInviteService.findOpenInvitation(emailAddress, team); boolean newInvitation = (invitation == null); if (newInvitation) { invitation = new Invitation(emailAddress, teamId); } else if (invitation.isDeclined()) { continue; }//from w ww . j a v a 2 s .c o m InvitationMessage invitationMessage = new InvitationMessage(form.getMessage(), inviterPersonId); invitation.addInvitationMessage(invitationMessage); invitation.setTimestamp(new Date().getTime()); invitation.setIntendedRole(form.getIntendedRole()); teamInviteService.saveOrUpdate(invitation); sendInvitationByMail(invitation, subject, form.getInviter(), locale); AuditLog.log( "Sent invitation and saved to database: team: {}, inviter: {}, email: {}, role: {}, hash: {}", teamId, inviterPersonId, emailAddress, form.getIntendedRole(), invitation.getInvitationHash()); } }
From source file:org.nuxeo.ecm.user.registration.actions.UserRegistrationActions.java
public void submitMultipleUserRegistration(String configurationName) throws AddressException { if (StringUtils.isBlank(multipleEmails)) { facesMessages.add(ERROR, resourcesAccessor.getMessages().get("label.registration.multiple.empty")); return;/*from ww w . j av a2s.c o m*/ } docinfo.setDocumentId(navigationContext.getCurrentDocument().getId()); InternetAddress[] emails = splitAddresses(multipleEmails); for (InternetAddress email : emails) { userinfo.setLogin(email.getAddress()); userinfo.setEmail(email.getAddress()); log.debug("Request email: " + email + " with multiple invitation."); doSubmitUserRegistration(configurationName); } resetPojos(); Events.instance().raiseEvent(REQUESTS_DOCUMENT_LIST_CHANGED); }
From source file:org.nuxeo.cm.mail.actionpipe.ExtractMessageInformation.java
@Override @SuppressWarnings("deprecation") public boolean execute(ExecutionContext context) throws MessagingException { File tmpOutput = null;/*from www . jav a 2 s .co m*/ OutputStream out = null; try { Message originalMessage = context.getMessage(); if (log.isDebugEnabled()) { log.debug("Transforming message, original subject: " + originalMessage.getSubject()); } // fully load the message before trying to parse to // override most of server bugs, see // http://java.sun.com/products/javamail/FAQ.html#imapserverbug Message message; if (originalMessage instanceof MimeMessage) { message = new MimeMessage((MimeMessage) originalMessage); if (log.isDebugEnabled()) { log.debug("Transforming message after full load: " + message.getSubject()); } } else { // stuck with the original one message = originalMessage; } Address[] from = message.getFrom(); if (from != null) { Address addr = from[0]; if (addr instanceof InternetAddress) { InternetAddress iAddr = (InternetAddress) addr; context.put(SENDER_KEY, iAddr.getPersonal()); context.put(SENDER_EMAIL_KEY, iAddr.getAddress()); } else { context.put(SENDER_KEY, addr.toString()); } } Date receivedDate = message.getReceivedDate(); if (receivedDate == null) { // try to get header manually String[] dateHeader = message.getHeader("Date"); if (dateHeader != null) { try { long time = Date.parse(dateHeader[0]); receivedDate = new Date(time); } catch (IllegalArgumentException e) { // nevermind } } } if (receivedDate != null) { Calendar date = Calendar.getInstance(); date.setTime(receivedDate); context.put(RECEPTION_DATE_KEY, date); } String subject = message.getSubject(); if (subject != null) { subject = subject.trim(); } if (subject == null || "".equals(subject)) { subject = "<Unknown>"; } context.put(SUBJECT_KEY, subject); String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader != null) { context.put(MESSAGE_ID_KEY, messageIdHeader[0]); } // TODO: pass it through initial context MimetypeRegistry mimeService = (MimetypeRegistry) context.getInitialContext().get(MIMETYPE_SERVICE_KEY); if (mimeService == null) { log.error("Could not retrieve mimetype service"); } // add all content as first blob tmpOutput = File.createTempFile("injectedEmail", ".eml"); Framework.trackFile(tmpOutput, tmpOutput); out = new FileOutputStream(tmpOutput); message.writeTo(out); Blob blob = Blobs.createBlob(tmpOutput, MESSAGE_RFC822_MIMETYPE, null, subject + ".eml"); List<Blob> blobs = new ArrayList<>(); blobs.add(blob); context.put(ATTACHMENTS_KEY, blobs); // process content getAttachmentParts(message, subject, mimeService, context); return true; } catch (IOException e) { log.error(e); } finally { IOUtils.closeQuietly(out); } return false; }