Skip to content

minosiants/pencil

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Pencil

Join the chat at https://gitter.im/minosiants/pencil build

Overview

Pencil is a simple smtp client. The main goal is to be able to send emails in the simplest way.
It is build on top of cats, cats-effect, fs2, scodec

Pencil supports:

  • Text email (ascii)
  • Mime email
  • TLS
  • Authentication

Specifications

Usage

Add dependency to your build.sbt

libraryDependencies += "com.minosiants" %% "pencil" % "0.6.3"

Examples how to use it

Create text email

val email = Email.text(
      from"user1@mydomain.tld",
      to"user1@example.com",
      subject"first email",
      Body.Ascii("hello")
)

Create mime email

val email = Email.mime(
     from"user1@mydomain.tld",
     to"user1@example.com",
     subject"привет",
     Body.Utf8("hi there")
) + attachment"path/to/file"

Send email

object Main extends IOApp {

  val logger    = Slf4jLogger.getLogger[IO]
  override def run(args: List[String]): IO[ExitCode] = {
    val credentials = Credentials(
      Username("user1@mydomain.tld"),
      Password("password")
    )
    val action = for {
      tls <- Network[IO].tlsContext.system
      client = Client[IO](SocketAddress(host"localhost", port"25"), Some(credentials))(tls,logger)
      response <- client.send(email)
    }yield response

    action.attempt
            .map {
              case Right(replies) =>
                println(replies)
                ExitCode.Success
              case Left(error) =>
                error match {
                  case e: Error => println(e.toString)
                  case e: Throwable => println(e.getMessage)
                }
                ExitCode.Error
            }
  }
}

Docker Mailserver

For test purposes Docker Mailserver can be used