CkJava Requires Chilkat v11.0.0+
CkJava
Find the text in an archived T-Mobile gateway email
See more Email Object Examples
Some archived gateway messages carry the SMS text as a related MIME item. Check for an ordinary text body first, then inspect related items by media type. The related-text branch assumes UTF-8, as in the sample format. It reads a saved email and needs no carrier service.
Chilkat CkJava 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;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmail email = new CkEmail();
success = email.LoadEml("gateway.eml");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
if (email.HasPlainTextBody() == true) {
System.out.println(email.getPlainTextBody());
return;
}
CkStringBuilder mediaType = new CkStringBuilder();
int i = 0;
while ((i < email.get_NumRelatedItems())) {
mediaType.SetString(email.getRelatedContentType(i));
if (mediaType.ContentsEqual("text/plain",false) == true) {
System.out.println(email.getRelatedString(i,"utf-8"));
return;
}
i = i+1;
}
System.out.println("No text body or related text/plain part.");
}
}