Sample code for 30+ languages & platforms
Java

Serialize MIME to a String

See more MIME Examples

Demonstrates the Chilkat Mime.GetMime method, which serializes and returns the complete MIME entity — headers, body, multipart boundaries, and all descendants — as a string. It takes no arguments.

Background: This produces the finished MIME text ready to send, store, or hand to another component — the inverse of loading. The whole tree is emitted, including generated multipart boundaries. Because it returns a string, it is best for text-safe content; when the body may contain raw binary bytes, serialize with GetMimeBd to a BinData instead so nothing is altered.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Mime;

public class ChilkatExample {

    public static void main(String[] args) {
        // Demonstrates the Mime.GetMime method, which serializes and returns the complete MIME entity
        // (headers, body, multipart boundaries, and all descendants) as a string.  It takes no
        // arguments.

        Mime mime = new Mime();

        // Build a simple MIME entity.
        String mimeText;
        try {
            mime.setBodyFromPlainText("Hello, this is the message body.");

            // Serialize it to a string.
            mimeText = mime.getMime();
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println(mimeText);
    }
}