• Stars
    star
    39
  • Rank 693,563 (Top 14 %)
  • Language
    Scala
  • License
    MIT License
  • Created about 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Emil is a library for dealing with E-Mail in Scala.

Emil - Email without a

Build Scaladex Scala Steward badge

[\/] Emil is a library for working with E-Mail in Scala. The api builds on Cats and FS2. It comes with a backend implementation that is based on the well known Java Mail library. As such it is just another wrapper library, but also a bit different:

  • Extensible DSL for creating mails in code.
  • Conveniently send mails via SMTP.
  • Search mail boxes via IMAP.
  • The data structures model a simplified E-Mail structure. Instead of adhering to the recursive structure of a mime message, a mail here is flat, consisting of a header, a body (text, html or both) and a list of attachments.
  • The data structures and api are in a separate module, that doesn't depend on a concrete implementation library, like Java Mail. An implementation based on fs2-mail or even EWS can be created without affecting the user code of this library.

Write your e-mail related code once and then decide how to execute.

Usage

With sbt, add the dependencies:

"com.github.eikek" %% "emil-common" % "0.15.0"  // the core library
"com.github.eikek" %% "emil-javamail" % "0.15.0" // implementation module
// … optionally, other modules analog

Emil is provided for Scala 2.12, 2.13 and 3. Note: from 0.10.0 emil is builta against CE3. Also from this version onwards, support for scala3 has been added.

Examples

Send a mail (returning its messageID):

import cats.effect._
import cats.data.NonEmptyList
import emil._, emil.builder._
import emil.javamail._

val mail: Mail[IO] = MailBuilder.build(
  From("[email protected]"),
  To("[email protected]"),
  Subject("Hello!"),
  CustomHeader(Header("User-Agent", "my-email-client")),
  TextBody("Hello!\n\nThis is a mail."),
  HtmlBody("<h1>Hello!</h1>\n<p>This <b>is</b> a mail.</p>"),
  AttachUrl[IO](getClass.getResource("/files/Test.pdf")).
    withFilename("test.pdf").
    withMimeType(MimeType.pdf)
)

val myemil = JavaMailEmil[IO]()
val smtpConf = MailConfig("smtp://devmail:25", "dev", "dev", SSLType.NoEncryption)

val sendIO: IO[NonEmptyList[String]] = myemil(smtpConf).send(mail)

Searching for mails:

import java.time._
import cats.effect._
import emil._
import emil.SearchQuery._
import emil.javamail._

val myemil = JavaMailEmil[IO]()
val imapConf = MailConfig("imap://devmail:143", "dev", "dev", SSLType.NoEncryption)

def searchInbox[C](a: Access[IO, C], q: SearchQuery): MailOp[IO, C, SearchResult[MailHeader]] =
  for {
    inbox  <- a.getInbox
    mails  <- a.search(inbox, 20)(q)
  } yield mails


val q = (ReceivedDate >= Instant.now.minusSeconds(60)) && (Subject =*= "test")
val searchIO: IO[SearchResult[MailHeader]] = myemil(imapConf).run(searchInbox(myemil.access, q))

Documentation

More information can be found here.

More Repositories

1

docspell

Assist in organizing your piles of documents, resulting from scanners, e-mails and other sources with miminal effort.
Elm
1,534
star
2

sharry

Sharry is a self-hosted file sharing web application.
Elm
825
star
3

chee

A command line tool for managing photos.
Scala
26
star
4

yamusca

Yet another mustache impl for scala
Scala
22
star
5

sbt-openapi-schema

Generate schema sources for Scala, Java and Elm from an openapi 3.0 spec.
Scala
20
star
6

calev

Work with systemd.time like calendar events in Scala
Scala
11
star
7

org-expenses

track expenses with org
Emacs Lisp
9
star
8

mpc4s

Scala client library for MPD, HTTP interface to MPD via REST/Websockets, finally a Webclient for MPD
Scala
9
star
9

sitebag

"read it later" (server) app in scala; for storing websites
Scala
5
star
10

confnix

my nixos config files
Nix
5
star
11

binny

Scala library for dealing with binaries/blobs in databases
Scala
4
star
12

publet

Template Web application
Scala
4
star
13

meth

Commandline client for mediathekview
Scala
4
star
14

swing-tasks

A small library that aims to help with executing tasks from swing applications.
Java
3
star
15

dotfiles

Shell
3
star
16

sig

simple image gallery -- static site generator for image galleries
Scheme
3
star
17

dlm

download manager for the command line
Common Lisp
2
star
18

scala-steward

Run scala-steward on my repos
Shell
2
star
19

porter

authentication / authorization service in scala
Scala
2
star
20

spray-openid

OpenId 2 support for use with spray
Scala
2
star
21

magnatune.el

Browse magnatune's music collection in emacs.
Emacs Lisp
2
star
22

webact

Run actions from the web. Webact allows to manage scripts on the server and execute them.
Elm
2
star
23

scue

Thin Scala wrapper for Blueprints Graph API.
Scala
2
star
24

publet-plantuml

PlantUML extensio for publet.
Scala
2
star
25

notelog

create a log of notes across multiple org files
Emacs Lisp
1
star
26

init.el

My Emacs configuration
Emacs Lisp
1
star
27

shelter

manage virtual accounts
Clojure
1
star
28

musicpds

Shell
1
star
29

neoswing

A simple swing-based GUI for Bluepints enabled databases, that uses the JUNG library for visuaization.
Java
1
star
30

publet-james

Extension for publet integrating Apache James.
Scala
1
star
31

wicket-quickstart-osgi

Java
1
star
32

swing-uploadfield

A swing component for url inputs.
Java
1
star
33

attentive

A personal scrobble daemon.
Scala
1
star
34

wicket-commons

Java
1
star
35

elv-modules

1
star
36

devshell-tools

A collection of tools for creating dev environments with nix flakes
Nix
1
star
37

htmx4s

Scala
1
star
38

county

Lightweight library for Scala for managing counters.
Scala
1
star
39

keeper

Scala
1
star