Java
Chilkat2 Java
Upload (Append) Email to an IMAP Mailbox
Upload / append an email to an IMAP mailbox.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.Imap;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Imap imap = new Imap();
// Connect to an IMAP server.
// Use TLS
imap.setSsl(true);
imap.setPort(993);
try {
imap.connect("imap.example.com");
// Login
imap.login("myLogin", "myPassword");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Email email = new Email();
// Load the email from a .eml file.
try {
email.loadEml("myEmail.eml");
imap.appendMail("Inbox", email);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Email uploaded to Inbox!");
// Disconnect from the IMAP server.
imap.disconnect();
}
}