List of usage examples for javax.mail.internet InternetAddress setPersonal
public void setPersonal(String name) throws UnsupportedEncodingException
From source file:com.fstx.stdlib.common.messages.MailSenderImpl.java
/** * @see com.ess.messages.MailSender#send() *///from w ww . j ava 2s . com public boolean send() { try { // 2005-11-27 RSC always requires authentication. Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", host.getAddress()); /* * 2005-11-27 RSC * Since webmail.us is starting to make other ports available * as Comcast blocks port 25. */ props.put("mail.smtp.port", host.getPort()); Session s = Session.getInstance(props, null); MimeMessage messageOut = new MimeMessage(s); InternetAddress fromOut = new InternetAddress(from.getAddress()); //reid 2004-12-20 fromOut.setPersonal(from.getName()); messageOut.setFrom(fromOut); InternetAddress toOut = new InternetAddress(this.to.getAddress()); //reid 2004-12-20 toOut.setPersonal(to.getName()); messageOut.addRecipient(javax.mail.Message.RecipientType.TO, toOut); messageOut.setSubject(message.getSubject()); messageOut.setText(message.getMessage()); if (host.useAuthentication()) { Transport transport = s.getTransport("smtp"); transport.connect(host.getAddress(), host.getUsername(), host.getPassword()); transport.sendMessage(messageOut, messageOut.getAllRecipients()); transport.close(); } else { Transport.send(messageOut); } } catch (Exception e) { log.info("\n\nMailSenderIMPL3: " + host.getAddress()); e.printStackTrace(); throw new RuntimeException(e); } return true; }
From source file:com.fsrin.menumine.common.message.MailSenderImpl.java
/** * @see com.ess.messages.MailSender#send() */// w w w . j a v a 2 s .com public boolean send() { try { Properties props = new Properties(); props.put("mail.smtp.host", host.getAddress()); if (host.useAuthentication()) { props.put("mail.smtp.auth", "true"); } Session s = Session.getInstance(props, null); s.setDebug(true); // PasswordAuthentication pa = new PasswordAuthentication(host // .getUsername(), host.getPassword()); // // URLName url = new URLName(host.getAddress()); // // s.setPasswordAuthentication(url, pa); MimeMessage messageOut = new MimeMessage(s); InternetAddress fromOut = new InternetAddress(from.getAddress()); //reid 2004-12-20 fromOut.setPersonal(from.getName()); messageOut.setFrom(fromOut); InternetAddress toOut = new InternetAddress(this.to.getAddress()); //reid 2004-12-20 toOut.setPersonal(to.getName()); messageOut.addRecipient(javax.mail.Message.RecipientType.TO, toOut); messageOut.setSubject(message.getSubject()); messageOut.setText(message.getMessage()); if (host.useAuthentication()) { Transport transport = s.getTransport("smtp"); transport.connect(host.getAddress(), host.getUsername(), host.getPassword()); transport.sendMessage(messageOut, messageOut.getAllRecipients()); transport.close(); } else { Transport.send(messageOut); } } catch (Exception e) { log.info("\n\nMailSenderIMPL3: " + host.getAddress()); e.printStackTrace(); throw new RuntimeException(e); } return true; }
From source file:org.tsm.concharto.web.feedback.FeedbackController.java
public MimeMessage makeFeedbackMessage(MimeMessage message, FeedbackForm feedbackForm, HttpServletRequest request) {/*from ww w . j a va 2 s .c om*/ //prepare the user info String requestInfo = getBrowserInfo(request); StringBuffer messageText = new StringBuffer(feedbackForm.getBody()) .append("\n\n=============================================================\n").append(requestInfo); InternetAddress from = new InternetAddress(); from.setAddress(feedbackForm.getEmail()); InternetAddress to = new InternetAddress(); to.setAddress(sendFeedbackToAddress); try { from.setPersonal(feedbackForm.getName()); message.addRecipient(Message.RecipientType.TO, to); message.setSubject(FEEDBACK_SUBJECT + feedbackForm.getSubject()); message.setText(messageText.toString()); message.setFrom(from); } catch (UnsupportedEncodingException e) { log.error(e); } catch (MessagingException e) { log.error(e); } return message; }
From source file:org.tsm.concharto.lab.LabJavaMail.java
private void sendConfirmationEmail(User user) { //mailSender.setHost("skipper"); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(user.getEmail());//w w w . j av a2s .c o m String messageText = StringUtils.replace(WELCOME_MESSAGE, PARAM_NAME, user.getUsername()); message.setText(messageText); message.setSubject(WELCOME_SUBJECT); message.setFrom("<Concharto Notifications> notify@concharto.com"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); MimeMessage mimeMessage = mailSender.createMimeMessage(); InternetAddress from = new InternetAddress(); from.setAddress("notify@concharto.com"); InternetAddress to = new InternetAddress(); to.setAddress(user.getEmail()); try { from.setPersonal("Concharto Notifications"); mimeMessage.addRecipient(Message.RecipientType.TO, to); mimeMessage.setSubject(WELCOME_SUBJECT); mimeMessage.setText(messageText); mimeMessage.setFrom(from); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } mailSender.setHost("localhost"); mailSender.send(mimeMessage); /* Confirm your registration with Concharto Hello sanmi, Welcome to the Concharto community! Please click on this link to confirm your registration: http://www.concharto.com/member/confirm.htm?id=:confirmation You can find out more about us at http://wiki.concharto.com/wiki/About. If you were not expecting this email, just ignore it, no further action is required to terminate the request. */ }
From source file:de.hybris.platform.acceleratorservices.email.impl.DefaultEmailService.java
protected InternetAddress createInternetAddress(final String emailAddress, final String displayName) throws EmailException { try {/* w w w . j ava 2 s .co m*/ final InternetAddress address = new InternetAddress(emailAddress); address.setPersonal(StringUtils.isNotBlank(displayName) ? displayName : emailAddress); address.validate(); return address; } catch (final AddressException e) { throw new EmailException(e); } catch (final UnsupportedEncodingException e) { throw new EmailException(e); } }
From source file:com.enonic.vertical.userservices.OrderHandlerController.java
private void sendMail(String receiverEmail, String receiverName, String senderEmail, String senderName, String subject, String message) throws MessagingException, UnsupportedEncodingException { // smtp server Properties smtpProperties = new Properties(); smtpProperties.put("mail.smtp.host", verticalProperties.getMailSmtpHost()); Session session = Session.getDefaultInstance(smtpProperties, null); // create message Message msg = new MimeMessage(session); // set from address if (senderEmail != null && !senderEmail.equals("")) { InternetAddress addressFrom = new InternetAddress(senderEmail); if (senderName != null && !senderName.equals("")) { addressFrom.setPersonal(senderName); }// w w w .ja va 2s.c o m msg.setFrom(addressFrom); } // set to address InternetAddress addressTo = new InternetAddress(receiverEmail); if (receiverName != null) { addressTo.setPersonal(receiverName); } msg.setRecipient(Message.RecipientType.TO, addressTo); // Setting subject and content type msg.setSubject(subject); message = RegexpUtil.substituteAll("(\\\\n)", "\n", message); msg.setContent(message, "text/plain; charset=UTF-8"); // send message Transport.send(msg); }
From source file:edu.stanford.muse.email.EmailFetcherStats.java
/** * intern a bunch of addrs, to save memory * * @throws UnsupportedEncodingException/*from w w w . j av a 2s . c o m*/ */ private static void internAddressList(Address[] addrs) throws UnsupportedEncodingException { if (addrs == null) return; for (Address a : addrs) { if (a instanceof InternetAddress) { InternetAddress ia = (InternetAddress) a; String address = ia.getAddress(), personal = ia.getPersonal(); if (address != null) ia.setAddress(InternTable.intern(address)); if (personal != null) ia.setPersonal(InternTable.intern(personal)); } } }
From source file:lucee.runtime.net.smtp.SMTPClient.java
private void checkAddress(InternetAddress ia, String charset) { // DIFF 23 try {/*from www.j av a 2 s . com*/ if (!StringUtil.isEmpty(ia.getPersonal())) { String personal = MailUtil.encode(ia.getPersonal(), charset); if (!personal.equals(ia.getPersonal())) ia.setPersonal(personal); } } catch (UnsupportedEncodingException e) { } }
From source file:org.bimserver.webservices.impl.ServiceImpl.java
@Override public void sendCompareEmail(SCompareType sCompareType, Long mcid, Long poid, Long roid1, Long roid2, String address) throws ServerException, UserException { requireRealUserAuthentication();//ww w . j a va2s. c om DatabaseSession session = getBimServer().getDatabase().createSession(); try { SUser currentUser = getCurrentUser(session); Revision revision1 = session.get(StorePackage.eINSTANCE.getRevision(), roid1, OldQuery.getDefault()); Revision revision2 = session.get(StorePackage.eINSTANCE.getRevision(), roid2, OldQuery.getDefault()); String senderName = currentUser.getName(); String senderAddress = currentUser.getUsername(); if (!senderAddress.contains("@") || !senderAddress.contains(".")) { senderAddress = getBimServer().getServerSettingsCache().getServerSettings().getEmailSenderAddress(); } EmailMessage message = getBimServer().getMailSystem().createMessage(); try { InternetAddress addressFrom = new InternetAddress(senderAddress); addressFrom.setPersonal(senderName); message.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[1]; addressTo[0] = new InternetAddress(address); message.setRecipients(Message.RecipientType.TO, addressTo); message.setSubject("BIMserver Model Comparator"); SCompareResult compareResult = compare(roid1, roid2, sCompareType, mcid); String html = CompareWriter.writeCompareResult(compareResult, revision1.getId(), revision2.getId(), sCompareType, getServiceMap().getServiceInterface().getProjectByPoid(poid), false); message.setContent(html, "text/html"); message.send(); } catch (AddressException e) { throw new UserException(e); } catch (UnsupportedEncodingException e) { throw new UserException(e); } catch (MessagingException e) { throw new UserException(e); } } catch (Exception e) { handleException(e); } finally { session.close(); } }
From source file:org.bimserver.webservices.Service.java
@Override public void sendCompareEmail(SCompareType sCompareType, SCompareIdentifier sCompareIdentifier, Long poid, Long roid1, Long roid2, String address) throws ServerException, UserException { DatabaseSession session = bimServer.getDatabase().createSession(); try {//from w w w .j ava 2 s . c om SUser currentUser = getCurrentUser(session); Revision revision1 = session.get(StorePackage.eINSTANCE.getRevision(), roid1, false, null); Revision revision2 = session.get(StorePackage.eINSTANCE.getRevision(), roid2, false, null); String senderName = currentUser.getName(); String senderAddress = currentUser.getUsername(); if (!senderAddress.contains("@") || !senderAddress.contains(".")) { senderAddress = bimServer.getSettingsManager().getSettings().getEmailSenderAddress(); } Session mailSession = bimServer.getMailSystem().createMailSession(); Message msg = new MimeMessage(mailSession); try { InternetAddress addressFrom = new InternetAddress(senderAddress); addressFrom.setPersonal(senderName); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[1]; addressTo[0] = new InternetAddress(address); msg.setRecipients(Message.RecipientType.TO, addressTo); msg.setSubject("BIMserver Model Comparator"); SCompareResult compareResult = compare(roid1, roid2, sCompareType, sCompareIdentifier); String html = CompareWriter.writeCompareResult(compareResult, revision1.getId(), revision2.getId(), sCompareType, getProjectByPoid(poid), false); msg.setContent(html, "text/html"); Transport.send(msg); } catch (AddressException e) { throw new UserException(e); } catch (UnsupportedEncodingException e) { throw new UserException(e); } catch (MessagingException e) { throw new UserException(e); } } finally { session.close(); } }