@Test @Disabled("Requires Gmail") void testGoogle_receiveUnseen() { ImapServer imapServer = MailServer.create() .host("imap.gmail.com") .port(993) .ssl(true) .auth("gmail_username", "gmail_password") .buildImapMailServer(); ReceiveMailSession session = imapServer.createSession(); session.open(); ReceivedEmail[] mails = session.receive() .filter(filter().flag(Flags.Flag.SEEN, false)) .unmark(Flags.Flag.SEEN) .fromFolder("INBOX") .get(); System.out.println(mails.length); Arrays.stream(mails).map(CommonEmail::subject).forEach(System.out::println); session.close(); } }
/** * Sets authenticator as {@link SimpleAuthenticator} using username and password. * * @param username The username to use. * @param password The password to use. * @return this */ public Builder auth(final String username, final String password) { Objects.requireNonNull(username, "Username cannot be null"); Objects.requireNonNull(password, "Password cannot be null"); return auth(new SimpleAuthenticator(username, password)); }
/** * Returns new mail server builder. */ public static Builder create() { return new Builder(); }
.host(LOCALHOST) .port(3025) .buildSmtpMailServer(); .host(LOCALHOST) .port(3143) .auth(GREEN, PWD) .buildImapMailServer(); .host(LOCALHOST) .port(3143) .auth(GREEN, PWD) .storeAttachmentsIn(attFolder) .buildImapMailServer();
.host(LOCALHOST) .port(3025) .buildSmtpMailServer(); .host(LOCALHOST) .port(3143) .auth(GREEN, PWD) .buildImapMailServer(); .host(LOCALHOST) .port(3143) .auth(GREEN, PWD) .buildImapMailServer();
.host(LOCALHOST) .port(3025) .buildSmtpMailServer(); .host(LOCALHOST) .port(3110) .auth(GREEN, PWD) .buildPop3MailServer(); final ReceiveMailSession session = popServer.createSession(); session.open();
@Test void testSendEmailWithVariousAttachaments() { final SmtpServer smtpServer = MailServer.create() .host(HOST) .auth(USERNAME, PASSWORD) .ssl(true) .buildSmtpMailServer(); final SendMailSession session = smtpServer.createSession(); session.open(); final Email email = Email.create() .from("info@jodd.org") .to("igor.spasic@gmail.com") .subject("test-gmail") .textMessage("Hello!") .htmlMessage( "<html><META http-equiv=Content-Type content=\"text/html; charset=utf-8\">" + "<body><h1>Hey!</h1><img src='cid:jodd.png'>" + "<h2>Hay!</h2><img src='cid:jodd2.png'>" + "<h3></h3></body></html>") .embeddedAttachment(EmailAttachment.with().content(new File(PNG)).inline(false)) .embeddedAttachment(EmailAttachment.with().content(new File(PNG)).contentId("jodd2.png").inline(true)) .attachment(EmailAttachment.with().content(PNG)); session.sendMail(email); session.close(); } }
/** * Sets authenticator as {@link SimpleAuthenticator} using username and password. * * @param username The username to use. * @param password The password to use. * @return this */ public Builder auth(final String username, final String password) { Objects.requireNonNull(username, "Username cannot be null"); Objects.requireNonNull(password, "Password cannot be null"); return auth(new SimpleAuthenticator(username, password)); }
@Test void testImap604() { ImapServer imapServer = MailServer.create() .ssl(true) .host("secureimap.t-online.de") .port(993) .auth("user", "password") .buildImapMailServer(); assertNotNull(imapServer); } }
/** * Returns new mail server builder. */ public static Builder create() { return new Builder(); }