Java
Java
Render an Email to MIME in a StringBuilder
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeSb method, which renders an Email object as MIME text and appends the result to a StringBuilder, without sending the email. This example renders a message into a StringBuilder and prints it.
Background: This is the
StringBuilder version of RenderToMime. Appending into a StringBuilder is more efficient when the MIME is large or when you plan to further inspect or manipulate it — searching, replacing, or accumulating additional text — without creating extra intermediate string copies.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Demonstrates the MailMan.RenderToMimeSb method, which renders an Email object as MIME text
// and appends the result to a StringBuilder (without sending the email).
CkMailMan mailman = new CkMailMan();
// Build the email to render.
CkEmail email = new CkEmail();
email.put_Subject("Rendered email");
email.put_From("alice@example.com");
email.AddTo("Bob","bob@example.com");
email.put_Body("This message is rendered to MIME in a StringBuilder.");
// Render the MIME into a StringBuilder.
CkStringBuilder sbMime = new CkStringBuilder();
success = mailman.RenderToMimeSb(email,sbMime);
if (success == false) {
System.out.println(mailman.lastErrorText());
return;
}
System.out.println(sbMime.getAsString());
}
}