Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retrieve the message-id from the message sent #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ worker*.log
project/.gnupg/
.bloop/
.metals/
.bsp/
.env
11 changes: 10 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,13 @@ lazy val courier = (project in file("courier"))
"org.jvnet.mock-javamail" % "mock-javamail" % "1.9" % Test
),
testFrameworks += new TestFramework("munit.Framework")
)
)
lazy val it = (project in file("integration-tests"))
.settings(commonSettings ++ cFlags)
.settings(
name := "courier-integration-tests",
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "0.7.27" % Test,
),
testFrameworks += new TestFramework("munit.Framework")
).dependsOn(courier)
6 changes: 4 additions & 2 deletions courier/src/main/scala/mailer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ case class Mailer(_session: MailSession = Defaults.session,
mimeMessageFactory: MailSession => MimeMessage = Defaults.mimeMessageFactory) {
def session = Session.Builder(this)

def apply(e: Envelope)(implicit ec: ExecutionContext): Future[Unit] = {
def apply(e: Envelope)(implicit ec: ExecutionContext): Future[Option[String]] = {
val msg = mimeMessageFactory(_session)

e.subject.foreach {
Expand All @@ -37,7 +37,9 @@ case class Mailer(_session: MailSession = Defaults.session,
}

Future {
Transport.send(msg)
// sending the email sets the message id
val _ = Transport.send(msg)
Option(msg.getMessageID())
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions integration-tests/src/test/scala/mailspec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package courier

import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._


class MailSpec extends munit.FunSuite {
// create a gmail app password https://myaccount.google.com/apppasswords
test("the mailer should send an email") {
assume(sys.env("CI").isEmpty(), "This test is meant to be ran locally.")
val email = sys.env("IT_EMAIL")
val password = sys.env("IT_PASSWORD")
val mailer = Mailer("smtp.gmail.com", 587)
.auth(true)
.as(email, password)
.startTls(true)()
val mId = Await.result(mailer(Envelope.from(email.addr)
.to(email.addr)
.subject("miss you")
.content(Text("hi mom"))), 10.seconds)
assert(mId.nonEmpty, "Message-ID should be set by the Transport.send call")
}
}
Loading