tags:

views:

84

answers:

3

how to convert String to message in java mail api?

+2  A: 

I'm not sure what you're after. Perhaps The Quintessential Program to Send E-Mail [J2EE] helps?

Key method being msg.setText(content).

aioobe
+1  A: 

If the String contains the message body, just take or create a Message object (like a MimeMessage) and use the setTextmethod.

Otherwise, if the String holds a 'full' email, you'll have to separate header and body (from the String) and could use the addHeaderLine() method to recreate a message header.

Andreas_D
A: 

You can use the MimeMessage constructor which accepts an InputStream. (See the JavaMail documentation)

Message msg = new MimeMessage(mySession, 
        new ByteArrayInputStream(myString.getBytes()));
DR