/** * Return the JavaMail {@code Session}, * lazily initializing it if hasn't been specified explicitly. */ public synchronized Session getSession() { if (this.session == null) { this.session = Session.getInstance(this.javaMailProperties); } return this.session; }
protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } };
public Transport getTransport() throws NoSuchProviderException { return session.getTransport(); }
/** * Obtain a Transport object from the given JavaMail Session, * using the configured protocol. * <p>Can be overridden in subclasses, e.g. to return a mock Transport object. * @see javax.mail.Session#getTransport(String) * @see #getSession() * @see #getProtocol() */ protected Transport getTransport(Session session) throws NoSuchProviderException { String protocol = getProtocol(); if (protocol == null) { protocol = session.getProperty("mail.transport.protocol"); if (protocol == null) { protocol = DEFAULT_PROTOCOL; } } return session.getTransport(protocol); }
/** * Checks that the message can be sent using AWS Simple E-mail Service. */ private void checkMessage(Message msg) throws MessagingException { if (msg == null) { throw new MessagingException("Message is null"); } if (!(msg instanceof MimeMessage)) { throw new MessagingException( "AWS Mail Service can only send MimeMessages"); } }
/** * Validate that this instance can connect to the server that it is configured * for. Throws a {@link MessagingException} if the connection attempt failed. */ public void testConnection() throws MessagingException { Transport transport = null; try { transport = connectTransport(); } finally { if (transport != null) { transport.close(); } } }
/** * Returns email store. * * @return {@link com.sun.mail.imap.IMAPStore} * @throws NoSuchProviderException if a provider for the given protocol is not found. */ protected Store getStore(final Session session) throws NoSuchProviderException { return session.getStore(PROTOCOL_IMAP); }
/** * Returns {@code true} if message is deleted. * * @return {@code true} if message is deleted. */ public boolean isDeleted() { return flags.contains(Flag.DELETED); }
/** * Closes folder if opened and expunge deleted messages. */ protected void closeFolderIfOpened(final Folder folder) { if (folder != null) { try { folder.close(true); } catch (final MessagingException ignore) { } } }
public AWSJavaMailTransport(Session session, URLName urlname) { super(session, urlname); this.accessKey = session.getProperty(AWS_ACCESS_KEY_PROPERTY); this.secretKey = session.getProperty(AWS_SECRET_KEY_PROPERTY); this.httpsEndpoint = session.getProperty(AWS_EMAIL_SERVICE_ENDPOINT_PROPERTY); }
/** * Creates a new {@link OutputStreamTransport}. * * @param session {@link Session}. */ public OutputStreamTransport(final Session session) { super(session, new URLName("JODD_MAIL_2_EML", null, -1, null, null, null)); }
/** * Marks messages as seen after receiving them. */ public ReceiverBuilder markSeen() { this.flagsToSet.add(Flags.Flag.SEEN); return this; }
/** * Returns {@code true} if mail session is still connected. * * @return {@code true} if mail session is still connected. */ public boolean isConnected() { return service.isConnected(); }
protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }
@Override public synchronized void close() throws MessagingException { if ("".equals(connectedHost)) { throw new MessagingException("close failure"); } this.closeCalled = true; }
/** * Returns {@code true} if message is seen. * * @return {@code true} if message is seen. */ public boolean isSeen() { return flags.contains(Flag.SEEN); }
@Override protected Transport getTransport(Session sess) throws NoSuchProviderException { assertEquals("bogusValue", sess.getProperty("bogusKey")); return super.getTransport(sess); } };
@Override public void connect(String host, int port, String username, String password) throws MessagingException { if (host == null) { throw new MessagingException("no host"); } this.connectedHost = host; this.connectedPort = port; this.connectedUsername = username; this.connectedPassword = password; setConnected(true); }
/** * Returns {@code true} if message is answered. * * @return {@code true} if message is answered. */ public boolean isAnswered() { return flags.contains(Flag.ANSWERED); }
/** * Returns {@code true} is message is flagged. * * @return {@code true} is message is flagged. */ public boolean isFlagged() { return flags.contains(Flag.FLAGGED); }