Sample code for 30+ languages & platforms
Java

Upload .eml File to an IMAP Mailbox

See more IMAP Examples

Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Imap;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        Imap imap = new Imap();

        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        // Connect to an IMAP server.
        // Use TLS
        imap.setSsl(true);
        imap.setPort(993);
        try {
            imap.connect("MY-IMAP-DOMAIN");

            // Login
            imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        StringBuilder sbMime = new StringBuilder();
        sbMime.loadFile("qa_data/eml/emoji_pizza.eml", "utf-8");

        // Upload to the mailbox.
        try {
            imap.appendMime("[Gmail]/testFolder", sbMime.getAsString());
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        imap.disconnect();

        System.out.println("OK.");
    }
}