Java
Java
Render an Email to MIME Bytes in a BinData
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.
Background: This is the binary version of
RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.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.RenderToMimeBd method, which renders an Email object as MIME
// bytes and appends the result to a BinData (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 bytes in a BinData.");
// Render the MIME into a BinData.
CkBinData bdMime = new CkBinData();
success = mailman.RenderToMimeBd(email,bdMime);
if (success == false) {
System.out.println(mailman.lastErrorText());
return;
}
System.out.println("Rendered MIME size (bytes) = " + bdMime.get_NumBytes());
}
}