public void sendBookingConfirmation(HttpServletRequest request, Booking booking) throws MailException, IOException { Mail mail = new Mail(); mail.setSubject(msg.get("BookingSuccessfulMailSubject")); mail.setBody( msg.get( "BookingSuccessfulMailBody", new Object[] { booking.getPlayer().toString(), FormatUtils.DATE_MEDIUM.print(booking.getBookingDate()), FormatUtils.TIME_HUMAN_READABLE.print(booking.getBookingTime()), booking.getName(), msg.get(booking.getPaymentMethod().toString()), booking.getAmount(), booking.getCurrency(), CANCELLATION_POLICY_DEADLINE, RequestUtil.getBaseURL(request) + "/bookings/booking/" + booking.getUUID() + "/cancel", RequestUtil.getBaseURL(request) + "/invoices/booking/" + booking.getUUID(), RequestUtil.getBaseURL(request) })); mail.addRecipient(booking.getPlayer()); mailUtils.send(mail, request); }
public void configure(URI uri) { String value = uri.getHost(); if (value != null) { setHost(value); } if (!isIgnoreUriScheme()) { String scheme = uri.getScheme(); if (scheme != null) { setProtocol(scheme); } } String userInfo = uri.getUserInfo(); if (userInfo != null) { setUsername(userInfo); } int port = uri.getPort(); if (port > 0) { setPort(port); } else if (port <= 0 && this.port <= 0) { // resolve default port if no port number was provided, and not already configured with a port // number setPort(MailUtils.getDefaultPortForProtocol(uri.getScheme())); } }
@Override public String toString() { if (mailMessage != null) { return "MailMessage: " + MailUtils.dumpMessage(mailMessage); } else { return "MailMessage: " + getBody(); } }
protected void sendMailMessage(Message message) throws MessagingException { // sent date message.setSentDate(Calendar.getInstance().getTime()); /* * Double check that the transport is still connected as some SMTP servers may * disconnect idle connections. */ if (!transport.isConnected()) { EndpointURI uri = endpoint.getEndpointURI(); if (logger.isInfoEnabled()) { logger.info("Connection closed by remote server. Reconnecting."); } transport.connect(uri.getHost(), uri.getPort(), uri.getUser(), uri.getPassword()); } transport.sendMessage(message, message.getAllRecipients()); if (logger.isDebugEnabled()) { StringBuffer msg = new StringBuffer(); msg.append("Email message sent with subject'") .append(message.getSubject()) .append("' sent- "); msg.append(", From: ").append(MailUtils.mailAddressesToString(message.getFrom())).append(" "); msg.append(", To: ") .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.TO))) .append(" "); msg.append(", Cc: ") .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.CC))) .append(" "); msg.append(", Bcc: ") .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.BCC))) .append(" "); msg.append(", ReplyTo: ").append(MailUtils.mailAddressesToString(message.getReplyTo())); logger.debug(msg.toString()); } }
public void sendNewBookingNotification(HttpServletRequest request, Booking booking) throws MailException, IOException { List<Contact> contactsToNotifyOnBooking = contactDAO.findAllForBookings(); if (!contactsToNotifyOnBooking.isEmpty()) { Mail mail = new Mail(); mail.setSubject( msg.get( "BookingSuccessfulMailSubjectAdmin", new Object[] { FormatUtils.DATE_HUMAN_READABLE.print(booking.getBookingDate()), FormatUtils.TIME_HUMAN_READABLE.print(booking.getBookingTime()), booking.getPlayer().toString() })); mail.setBody(msg.get("BookingSuccessfulMailBodyAdmin", getDetailBody(request, booking))); mail.setRecipients(contactsToNotifyOnBooking); mailUtils.send(mail, request); } }
protected void initialise(UMOEndpointURI endpoint) throws MessagingException { if (!initialised.get()) { String inbox = null; if (connector.getProtocol().equals("imap") && endpoint.getParams().get("folder") != null) { inbox = (String) endpoint.getParams().get("folder"); } else { inbox = Pop3Connector.MAILBOX; } URLName url = new URLName( endpoint.getScheme(), endpoint.getHost(), endpoint.getPort(), inbox, endpoint.getUsername(), endpoint.getPassword()); session = MailUtils.createMailSession(url); session.setDebug(logger.isDebugEnabled()); Store store = session.getStore(url); store.connect(); folder = store.getFolder(inbox); if (!folder.isOpen()) { try { // Depending on Server implementation it's not always // necessary // to open the folder to check it // Opening folders can be exprensive! // folder.open(Folder.READ_ONLY); folder.open(Folder.READ_WRITE); } catch (MessagingException e) { logger.warn("Failed to open folder: " + folder.getFullName(), e); } } } }