GithubHelp home page GithubHelp logo

email4j's Introduction

Email4J Build Status

Email4J (Email for Java) is a high level java library built on top of the javax.mail api for managing and sending emails, without the necessity of knowing any specifications of the underlying transports.

There are several entities that wrap the low level objects that the transport handles to give the developer a friendly and easy way to deal with mailboxes.

How to get it

You can include this library in your project using maven by adding the artifact and repository as follows.

<groupId>desi.juan</groupId>
<artifactId>email4j</artifactId>
<version>1.0-SNAPSHOT</version>
<repository>
    <id>email4j-repo</id>
    <url>https://raw.github.com/juandesi/email4j/mvn-repo/</url>
</repository>

NOTE: this is a custom repository deployed into a github branch.

Introduction

Basically you have 3 different clients for connecting with mailboxes.

  • a SmtpClient
  • a Pop3Client
  • an ImapClient

Each client has a specific set of operations that work for the underlying used protocol, some clients may share operations. i.e: the Pop3Client and the ImapClient share the retrieve operation (with differences but they both retrieve emails).

The SmtpClient

This client is mainly used to send emails, it's composed by only one operation send that receives an email and sends it to the specified recipients.

SmtpClient client = new SmtpClient("juan", "desimoni", "juan.smtp.host", SmtpClient.DEFAULT_SMTP_PORT, new ClientConfiguration());
client.send(email) // pre-built outgoing email.

To build outgoing emails Email4J provides a simple builder, the EmailBuilder.

EmailBuilder.newEmail()
        .withSubject("This is an email subject")
        .to(singletonList("[email protected]"))
        .withBody("Body of the message")
        .addAttachment(new EmailAttachment("id", "AttachmentContent", "text/plain; charset=UTF-8"))
        .build();

Of course there are other options for more complex body objects and attachments.

The ImapClient

The ImapClient talks directly to a mailbox where you can retrieve, move, mark or delete emails.

ImapClient client = new ImapClient("juan", "desimoni", "juan.imap.host", ImapClient.DEFAULT_IMAPS_PORT, new ClientConfiguration());

The main ImapClient operation is the retrieve operation, you only need to specify a folder and the client will retrieve all the emails contained in it. Also a boolean value is required for this operation since the IMAP protocol provides the capability to fetch emails without opening their content, this means not marking the email as SEEN email, but no body and attachments will be available in the resultant emails.

imapClient.retrieve(EmailConstants.INBOX_FOLDER, true);

The Pop3Client

The Pop3Client talks directly to a mailbox where you can retrieve, move, delete emails. There a lot of similarities between the ImapClient and this one, but the POP3 protocol have some restrictions or limitations since is an older protocol and it's oriented for local working.

Pop3Client client = new Pop3Client("juan", "desimoni", "juan.pop3.host", Pop3Client.DEFAULT_POP3S_PORT, new ClientConfiguration());

Of course we also have a retrieve operation like the ImapClient, the difference between the Imap operation and this one, is that the POP3 transport does not provide the capability to NOT open the fetched emails, so all the emails are READ and opened always. (emails are not really read in POP3 since the concept does not exist.)

pop3Client.retrieve(EmailConstants.INBOX_FOLDER);

More complex configurations

The ClientConfiguration enables the construction of more complex configurations to enable encrypted conections using TLS/SSL and injecting custom properties to the underlying protocol if requeried.

email4j's People

Contributors

jhult avatar juandesi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

email4j's Issues

SSL not implemented

I only see interfaces with TODOs for implementations in api/security - the docs say there is a possibility for "advanced configuration" with TLS etc., so is this package incomplete?
I need to connect to an IMAP server over SSL, but this client keeps timing out.
Works from shell:

openssl s_client -connect localhost:993 -crlf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.