I plan on sending a weekly email to each of my consumers, for exemple send email every Monday morning but depending in local time of consumers (some consumer are in USA others in French , Australie, China, ..), Is there any way to do a scheduler in Scala to know exactly when to send the email. (I'm using mailJet Api to send email)
Asked
Active
Viewed 378 times
2 Answers
1
In future, you can also use the new Email Automation scenario which Mailjet will release soon (several weeks). It will allow you to insert contact data with type "datetime" and later on trigger automated emails based on it. Stay tuned!

Zhivko
- 301
- 1
- 3
0
import akka.actor.ActorSystem
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
val nextMonday = LocalDate.now() `with` TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY)
val nextMondayMillis = nextMonday.toEpochDay
val actorSystem = ActorSystem("akka")
actorSystem.scheduler.schedule(nextMondayMillis - System.currentTimeMillis() milliseconds, 7 days){
//your email sending code here
}
Also add Akka to your dependencies.

Alexander Arendar
- 3,365
- 2
- 26
- 38
-
i try your solution but i get error : type mismatch; found : Long required: scala.concurrent.duration.FiniteDuration actorSystem.scheduler.schedule(nextMondayMillis - System.currentTimeMillis(), 7 days) { – salma1 Aug 03 '17 at 14:44
-
I've edited. Try now. It will schedule the first sending to the first next Monday. If you need to debug - you need to use different parameters for the `schedule` method. – Alexander Arendar Aug 03 '17 at 14:58
-
the code bellow send email just first monday, not every monday ?? – salma1 Aug 03 '17 at 15:37
-
@salma1 probably you could open scaladoc for the `schedule` method and read a bit on its parameters? The first parameter is an initial delay. So if you run this code on Wednesday then if will calculate how long it needs to wait till the next Monday to fire the first run. The seconds parameter `7 days` means that it will repeat running after the first time every 7 days, i.e. every week. – Alexander Arendar Aug 03 '17 at 15:44