<commit_before>Java Mail + Builder pattern
===========================

EmailBuilder v1.0
License: MIT

SUMMARY
------

Sending emails is a common programming task in enterprise computing. The Java mail implementation is a very good starting point for performing this task, but it's quite verbose and most times feels very procedural in nature. During a recent project (as of November 2012) I thought to myself: what if we hid all the procedural nastiness in a fluent API that's easy to understand? After a furious night of coding and learning, the EmailBuilder project/snippet was born. In essence, it's Joshua Boch's builder pattern sitting on top of the Java mail APIs. Through a session provider builder implementation it can handle the following types of authentication:

- Username/Password
- SSL Certificate
- TLS security
- Unauthenticated security

By using the session provider builder classes you can build out whichever one of these session types you need and then pass that to an email builder to create and send the email. In addition to authentication, the builder also accepts template substitutions via the StringTemplate class. This is your one-stop fluent shop for mail-merge and email origination.


Comments and critiques are welcome, and feel free to use it in your own projects. If you do any vast improvements to the code base, I'd appreciate a pull request.

EXAMPLES:
---------

Send an email using unauthenticated security.
```java
    SessionProvider session = SessionProvider.unauthenticated("username", "password");

    EmailBody body = EmailBody.builder()
            .content("This is my email body")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .cc(new InternetAddress("<EMAIL>"))
            .bcc(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

Send an email using TLS security.
```java
	SessionProvider session = AuthenticatedSessionProvider.host("my.mail.host").tlsAuth("user", "pass");

    EmailBody body = EmailBody.builder()
            .content("This is my email body")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

Send an email while defining some replacements.
```java
    SessionProvider session = SessionProvider.unauthenticated("username", "password");

    EmailBody body = EmailBody.builder()
            .replace("$name$", "jduv")
            .delimiter('$')
            .content("Hello $name$!")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

TODO:
-----<commit_msg>Fixing exmaples.<commit_after>Java Mail + Builder pattern
===========================

EmailBuilder v1.0
License: MIT

SUMMARY
------

Sending emails is a common programming task in enterprise computing. The Java mail implementation is a very good starting point for performing this task, but it's quite verbose and most times feels very procedural in nature. During a recent project (as of November 2012) I thought to myself: what if we hid all the procedural nastiness in a fluent API that's easy to understand? After a furious night of coding and learning, the EmailBuilder project/snippet was born. In essence, it's Joshua Boch's builder pattern sitting on top of the Java mail APIs. Through a session provider builder implementation it can handle the following types of authentication:

- Username/Password
- SSL Certificate
- TLS security
- Unauthenticated security

By using the session provider builder classes you can build out whichever one of these session types you need and then pass that to an email builder to create and send the email. In addition to authentication, the builder also accepts template substitutions via the StringTemplate class. This is your one-stop fluent shop for mail-merge and email origination.


Comments and critiques are welcome, and feel free to use it in your own projects. If you do any vast improvements to the code base, I'd appreciate a pull request.

EXAMPLES:
---------

Send an email using unauthenticated security.
```java
    SessionProvider session = SessionProvider.unauthenticated();

    EmailBody body = EmailBody.builder()
            .content("This is my email body")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .cc(new InternetAddress("<EMAIL>"))
            .bcc(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

Send an email using TLS security.
```java
	SessionProvider session = AuthenticatedSessionProvider.host("my.mail.host").tlsAuth("user", "pass");

    EmailBody body = EmailBody.builder()
            .content("This is my email body")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

Send an email while defining some replacements.
```java
    SessionProvider session = SessionProvider.unauthenticated();

    EmailBody body = EmailBody.builder()
            .replace("$name$", "jduv")
            .delimiter('$')
            .content("Hello $name$!")
            .build();

    Email.session(session)
            .from(new InternetAddress("<EMAIL>"))
            .to(new InternetAddress("<EMAIL>"))
            .subject("Hello world")
            .body(body)
            .build()
            .send();
```

TODO:
-----
{'fraction_non_alphanumeric': 0.10776361529548088, 'fraction_numerical': 0.001986426088395961, 'mean_word_length': 2.81198738170347, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5841394', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1450, 'n_words': 613}