

A Non-blocking "Email sending" functionality in Scala - Knoldus Blogs
source link: https://blog.knoldus.com/non-blocking-email-sending-functionality-scala/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A Non-blocking "Email sending" functionality in Scala
Reading Time: < 1 minute
In our last blog “Adding an Email Sending Functionality in Play using Scala” we explained how to include an Email sending functionality in a Play Scala Application. But the way in which we implemented it, made it a Blocking one i.e., application will wait until email has been sent.
In this blog we will explain, how to make the Email Sending functionality a Non-blocking one. By making it non-blocking, the application will not wait until email is sent & will move on to the next step.
To make this functionality a Non-Blocking one, just make following changes in the mailSendingApp we posted earlier:-
1) Import following packages in Application.scala file
xxxxxxxxxx
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
2) Add following code to Application.scala file
xxxxxxxxxx
def sendMail: Action[play.api.mvc.AnyContent] = Action { implicit request =>
mailForm.bindFromRequest.fold (
formWithErrors => {
Redirect("/")
},
mailData => {
Future {sendEmail(mailData.email)}
Redirect("/")
})
}
def sendEmail(email: String): Unit = {
val mail = use[MailerPlugin].email
mail.setSubject("Email sent using Scala")
mail.addRecipient(email)
mail.addFrom(email)
mail.send("Hello World")
}
Note – To download the App with changes just click here.
Recommend
-
11
Extending Functionality Reading Time: 2 minutesWe had an interesting case of enhancing the functionality of a logging library with our own case to feed data into DataDog....
-
10
Adding an Email sending functionality in Play using Scala Reading Time: < 1 minuteTo provide an Email Sending functionality in your Play App that is being built with Play 2.2.1, follow these steps ( this post...
-
11
Scripting Library in Scala – Ammonite Reading Time: 4 minutesAmmonite is a Scala library that lets us use Scala language f...
-
5
Self-Learning Kafka Streams with Scala Reading Time: 2 minutesA few days ago, I came across a situation where I wanted to do a stateful operation on the streaming data. So, I started finding possible solutions f...
-
7
Knoldus Newsletter Reading Time: < 1 minuteWe are back again with August 2014, Newsletter. Here is this Scala in Business | Knoldus Newsletter – August 2014 In thi...
-
10
A Beginner's Guide to Scala 3.0 Knoldus Blog Audio Reading Time: 6 minutes Dotty, a comprehensive name for all the things that are being added to Scala 3.0 has been a to...
-
10
Scala’s evolving ecosystem – Introduction to Scala.js Written by
-
17
Asynchronous Programming with Scala's Future & Promises Reading Time: < 1 minuteIn this presentation, we are going to discuss about Scala’s Future and Promise,their usage and Future composition and brief...
-
7
Implicit Conversions In Scala: Let’s extend Functionality Reading Time: 3 minutes Hello folks, in this blog we will see Im...
-
9
Solana – Wallet Creation and Sending Tokens Reading Time: 4 minutes Solana is an open-source project impl...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK