Simple smtp client
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:
Add dependency to your build.sbt
libraryDependencies += "com.minosiants" %% "pencil" % "2.0.0"
libraryDependencies += "com.minosiants" %% "pencil" % "1.2.0"
val email = Email.text(
from"user name <[email protected]>",
to"[email protected]",
subject"first email",
Body.Ascii("hello")
)
val email = Email.mime(
from"[email protected]",
to"[email protected]",
subject"привет",
Body.Utf8("hi there")
) + attachment"path/to/file"
val email = Email.mime(
from"[email protected]",
to"[email protected]",
subject"привет",
Body.Alternative(List(Body.Utf8("hi there3"), Body.Ascii("hi there2")))
)
object Main extends IOApp {
val logger = Slf4jLogger.getLogger[IO]
override def run(args: List[String]): IO[ExitCode] = {
val credentials = Credentials(
Username("[email protected]"),
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
}
}
}
For test purposes Docker Mailserver can be used