Java Requires Chilkat v11.0.0+
Java
Forward an email as an attachment
See more Email Object Examples
Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
public class ChilkatExample {
public static void main(String[] args) {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Email original = new Email();
try {
original.loadEml("message.eml");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Email email = new Email();
email.setFrom("Sam Lee <sam@example.com>");
try {
email.addTo("Alex Rivera", "alex@example.net");
email.setSubject("Forwarded message");
email.setBody("The original email is attached.");
email.attachEmail(original);
email.saveEml("forward-as-attachment.eml");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Saved forward-as-attachment.eml.");
}
}