Question

I did some searching around, and while I could find plenty of good posts on how to send emails in Java, I couldn't quite find a good jumping off point for displaying them. Here's the deal, my Spring 3 web-app has just received an object of type,

javax.mail.internet.MimeMessage

(More accurately it just built one that is now read to send.)

How would I go about displaying a preview of that message in HTML? I know that I could just keep track of everything that get puts into it, but there are header and footer, signature, etc. components that get built in beyond my reach.

Was it helpful?

Solution

If your concern is iterating through a non-trivial number of fields, why not use an ObjectMapper? For example, an org.springframework.web.servlet.view.json.MappingJacksonJsonView could send JSON data to the UI, and would also keep UI in charge of rendering of that data.

You can pass this to the ``:

<bean id="contentNegotiatingViewResolver"
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
    p:defaultContentType="text/html">       
    <property name="mediaTypes">
        <map>
            <entry key="xml" value="application/xml" />
            <entry key="json" value="application/json" />
            <entry key="${mimeKey}" value="${mimeMessageType} />
        </map>
    </property>
    <property name="defaultViews">
        <list>
            <bean
                class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
                p:objectMapper-ref="objectMapper" />
            <bean class="org.springframework.web.servlet.view.xml.MarshallingView"
                p:marshaller-ref="objectMarshaller" />
        </list>
    </property>
    ...
</bean>

OTHER TIPS

Handling all the cases is a non-trivial task. Perhaps one of the products in the JavaMail Third Party Products list has some reusable code?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top