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
- RFC 5321 - Simple Mail Transfer Protocol
- Multipurpose Internet Mail Extensions
- RFC 2045 - Part one - Format of Internet message bodies
- RFC 2046 - Part two - Media Types
- RFC 2047 - Part three - Message Header Extensions for Non-ASCII Text
- RFC 2049 - Part five - Confirmance criteria and examples
- RFC 4288 - Media Type Specifications and Registration Procedures
- RFC 1521 - MIME Part one - Mechanisms for Specifying and Describing the Format of Internet Message Bodies
- RFC 1522 - MIME Part two - Message Header Extensions for Non-ASCII Text
- RFC 4954 - SMTP Service Extension for Authentication
Add dependency to your build.sbt
libraryDependencies += "com.minosiants" %% "pencil" % "0.6.3"
val email = Email.text(
from"user1@mydomain.tld",
to"user1@example.com",
subject"first email",
Body.Ascii("hello")
)
val email = Email.mime(
from"user1@mydomain.tld",
to"user1@example.com",
subject"привет",
Body.Utf8("hi there")
) + attachment"path/to/file"
object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Blocker[IO]
.use { blocker =>
SocketGroup[IO](blocker).use { sg =>
TLSContext.system[IO](blocker).flatMap { tls =>
val credentials = Credentials(
Username("user1@example.com"),
Password("12345678")
)
val client = Client[IO]("localhost", 25, Some(credentials))(blocker, sg, tls)
val result = client.send(email)
result.attempt
.map {
case Right(value) =>
ExitCode.Success
case Left(error) =>
error match {
case e: Error => println(e.show)
case e: Throwable => println(e.getMessage)
}
ExitCode.Error
}
}
}
}
For test purposes Docker Mailserver can be used