项目作者: minosiants

项目描述 :
Simple smtp client
高级语言: Scala
项目地址: git://github.com/minosiants/pencil.git
创建时间: 2020-02-27T21:02:57Z
项目社区:https://github.com/minosiants/pencil

开源协议:Apache License 2.0

下载


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

for scala 3

  1. libraryDependencies += "com.minosiants" %% "pencil" % "2.0.0"

for scala 2.13

  1. libraryDependencies += "com.minosiants" %% "pencil" % "1.2.0"

Examples how to use it

Create text email

  1. val email = Email.text(
  2. from"user name <user1@mydomain.tld>",
  3. to"user1@example.com",
  4. subject"first email",
  5. Body.Ascii("hello")
  6. )

Create mime email

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

Create mime email

  1. val email = Email.mime(
  2. from"user1@mydomain.tld",
  3. to"user1@example.com",
  4. subject"привет",
  5. Body.Alternative(List(Body.Utf8("hi there3"), Body.Ascii("hi there2")))
  6. )

Send email

  1. object Main extends IOApp {
  2. val logger = Slf4jLogger.getLogger[IO]
  3. override def run(args: List[String]): IO[ExitCode] = {
  4. val credentials = Credentials(
  5. Username("user1@mydomain.tld"),
  6. Password("password")
  7. )
  8. val action = for {
  9. tls <- Network[IO].tlsContext.system
  10. client = Client[IO](SocketAddress(host"localhost", port"25"), Some(credentials))(tls,logger)
  11. response <- client.send(email)
  12. }yield response
  13. action.attempt
  14. .map {
  15. case Right(replies) =>
  16. println(replies)
  17. ExitCode.Success
  18. case Left(error) =>
  19. error match {
  20. case e: Error => println(e.toString)
  21. case e: Throwable => println(e.getMessage)
  22. }
  23. ExitCode.Error
  24. }
  25. }
  26. }

Docker Mailserver

For test purposes Docker Mailserver can be used