List of usage examples for org.apache.commons.mail Email getMimeMessage
public MimeMessage getMimeMessage()
From source file:org.sakaiproject.kernel.messaging.email.EmailMessagingService.java
public String send(Email email) throws MessagingException, JMSException { try {// www .ja va 2 s . c o m email.buildMimeMessage(); } catch (Exception e) { // this is a lossy cast. This would be a commons EmailException // this up cast is to keep commons-email out of our direct bindings throw new MessagingException(e); } ByteArrayOutputStream os = new ByteArrayOutputStream(); try { email.getMimeMessage().writeTo(os); } catch (javax.mail.MessagingException e) { throw new MessagingException(e); } catch (IOException e) { throw new MessagingException(e); } String content = os.toString(); Connection conn = connectionFactory.createTopicConnection(); conn.setClientID(getNextId()); Session clientSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination emailTopic = clientSession.createTopic(emailQueueName); MessageProducer client = clientSession.createProducer(emailTopic); ObjectMessage mesg = clientSession.createObjectMessage(content); mesg.setJMSType(emailJmsType); client.send(mesg); // TODO finish this return null; }