本文整理汇总了Scala中play.api.libs.mailer.MailerClient类的典型用法代码示例。如果您正苦于以下问题:Scala MailerClient类的具体用法?Scala MailerClient怎么用?Scala MailerClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MailerClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ForgotPasswordController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.{ AuthTokenService, UserService }
import models.daos._
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.mailer.{ Email, MailerClient }
import play.api.mvc.Controller
import utils.auth.DefaultEnv
import scala.concurrent.Future
class ForgotPasswordController @Inject() (
val messagesApi: MessagesApi,
silhouette: Silhouette[DefaultEnv],
userService: UserService,
authTokenService: AuthTokenService,
mailerClient: MailerClient,
envDAO: EnvDAO
)
extends Controller with I18nSupport {
def view = silhouette.UnsecuredAction.async { implicit request =>
Future.successful(Ok(views.html.forgotPassword(new myform.MyForgotPasswordForm())))
}
def submit = silhouette.UnsecuredAction.async { implicit request =>
new myform.MyForgotPasswordForm().bindFromRequest match {
case form: myform.MyForgotPasswordForm => Future.successful(BadRequest(views.html.forgotPassword(form)))
case data: myform.MyForgotPasswordFormData => {
val email = data.email
val loginInfo = LoginInfo(CredentialsProvider.ID, email)
val result = Redirect(routes.SignInController.view()).flashing("info" -> Messages("reset.email.sent"))
userService.retrieve(loginInfo).flatMap {
case Some(user) if user.email.isDefined =>
authTokenService.create(user.userID).map { authToken =>
val url = routes.ResetPasswordController.view(authToken.id).absoluteURL()
println("url " + url)
if (envDAO.getDosendmail) mailerClient.send(Email(
subject = Messages("email.reset.password.subject"),
from = Messages("email.from"),
to = Seq(email),
bodyText = Some(views.txt.emails.resetPassword(user, url).body),
bodyHtml = Some(views.html.emails.resetPassword(user, url).body)
))
result
}
case None => Future.successful(result)
}
}
}
}
}
示例2: MasterActor
//设置package包名称以及导入依赖的类
package actors
import java.util.Date
import javax.inject.Inject
import akka.actor.Actor
import models.HourlyMessage
import play.api.libs.mailer.MailerClient
import play.api.libs.ws.WSClient
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}
import reactivemongo.play.json.collection.JSONCollection
import play.api.libs.json.Json
import play.modules.reactivemongo.json._
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}
import reactivemongo.api.ReadPreference
import reactivemongo.play.json.collection.JSONCollection
import services.Counter
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class MasterActor @Inject()(mailerClient: MailerClient, val reactiveMongoApi: ReactiveMongoApi, ws: WSClient,counter: Counter) extends Actor with MongoController with ReactiveMongoComponents {
override val database = reactiveMongoApi.connection.database("dummy")
def receive = {
case HourlyMessage(message) => {
def patternFuture: Future[JSONCollection] = database.map(_.collection[JSONCollection]("testdb"))
val date = new Date()
val _count = counter.nextCount().toString
val _date = date.toString
for{
pattern <- patternFuture
lastError <- pattern.insert(Json.obj("count"-> _count,"date" -> _date))
}yield{
//Ok("Mongo LastError: %s".format(lastError))
println("count "+_count)
var status = 0
if(lastError.hasErrors){
status = 0
} else{
status = 1
}
status
}
}
}
}
示例3: MailerUtils
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.utils
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import akka.actor.ActorSystem
import lunatech.lunchplanner.common.DBConnection
import lunatech.lunchplanner.persistence.UserTable
import play.api.Configuration
import play.api.libs.mailer.{Email, MailerClient}
import com.github.nscala_time.time.Imports._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
class MailerUtils @Inject()(mailerClient: MailerClient, configuration: Configuration, implicit val connection: DBConnection) {
private def timeToNextMonday = {
val today = LocalDate.now
val dayOfWeek = today.getDayOfWeek
val nextMonday = today.plusDays(8 - dayOfWeek)
val nextMondayTime = nextMonday.toDateTime(new LocalTime(15, 30))
(nextMondayTime.getMillis - System.currentTimeMillis) / (1000 * 60)
}
def send(sendTo: List[String], body: String): String = {
val email: Email = Email("Friday Lunch", "@Lunatech <[email protected]>", sendTo, bodyHtml = Some(body))
mailerClient.send(email)
}
val system = ActorSystem("mailer-system")
system.scheduler.schedule(
Duration.create(timeToNextMonday, TimeUnit.MINUTES),
Duration.create(7, TimeUnit.DAYS))(sendMail())
def sendMail() = {
val users = UserTable.getAll.map(user => user.map(_.emailAddress).toList)
users.map(usersList => send(usersList, views.html.mail.render(configuration.getString("lunatech.email").getOrElse("[email protected]")).body))
}
}
示例4: EmailUtil
//设置package包名称以及导入依赖的类
package util
import javax.inject.{Singleton, Inject}
import dao.{UserDAO, CourseDAO, FacultyDAO, CMRDAO}
import models.User
import play.api.libs.mailer.{Email, MailerClient}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
@Singleton
class EmailUtil @Inject()(mailerClient: MailerClient, cmrDAO: CMRDAO, courseDAO: CourseDAO,
facultyDAO: FacultyDAO, userDAO: UserDAO) {
def send(email: Email): Future[Unit] = {
Future.successful(mailerClient.send(email).map(_ => ()))
}
def buildEmailNotifyNewAction(cmrId: Int, status: String, title: String,
courseId: String, faculty: String, toEmail: Seq[String], userName: String): Email = {
val subject = s"""CMR Center notification: CMR no.${cmrId} has been ${status}"""
val from = "Course Monitoring Report Center<[email protected]>"
val text = Some(
s"""CMR center inform that:
|Course ${title} - ${courseId} of ${faculty} have been ${status} by ${userName}.
|
|* The CMR must be commented on within 14 days.
|Please check more detail in:
|http://localhost:9000/report/${cmrId}
|""".stripMargin)
Email(subject, from, toEmail, text)
}
def buildEmailDaily(cmrId: Int, status: String, title: String, courseId:String, faculty:String,
toEmail: Seq[String], userName: String, aboutDate: Int): Email = {
val subject = s"""CMR Center notification: CMR no.${cmrId} has been approved about ${aboutDate} days"""
val from = "Course Monitoring Report Center<[email protected]>"
val text = Some(
s"""CMR center inform that:
|Course ${title} - ${courseId} of ${faculty} have been ${status} by ${userName}.
|
|* The CMR must be commented on within 14 days.
|* CMR that does not commented will be reject (left: ${14-aboutDate}).
|Please check more detail in:
|http://localhost:9000/report/${cmrId}
|""".stripMargin)
Email(subject, from, toEmail, text)
}
}
示例5: MailsendActor
//设置package包名称以及导入依赖的类
package actors
import play.api.Logger
import akka.actor.{Props, Actor}
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.mailer.{MailerClient, Email}
import com.typesafe.config.ConfigFactory
import javax.inject.Inject
object MailsendActor {
def props(mc: MailerClient) = Props(classOf[MailsendActor], mc)
}
class MailsendActor @Inject()(mc: MailerClient) extends Actor {
val config = ConfigFactory.load()
val mailFrom = config.getString("notify.mail.from")
val mailTo = config.getString("notify.mail.to")
val Subject = "play ???"
val MailBody = "????\n\n????"
override def receive: Receive = {
case "mailsend" => {
Logger.info((new java.util.Date).toString)
Logger.info("Mailsend Message received")
val email = Email(
Subject,
mailFrom,
Seq(mailTo),
bodyText = Some(MailBody),
bodyHtml = Some("")
)
//mc.send(email)
Logger.info("Mail sent")
}
}
}
示例6: Mailer
//设置package包名称以及导入依赖的类
package utils
import play.api.libs.mailer.{Email, MailerClient}
class Mailer(
settings: Settings,
mailerClient: MailerClient
) {
def confirm(victimName: String, userName: String, to: String = settings.Mail.all, toName: String = "All", subject : String = "Croissants") = {
send(Email(
subject = subject,
from = "Zencroissants <"+ settings.Mail.contact +">",
to = Seq(toName + "<"+ to +">"),
bodyHtml = Some(views.html.email.confirmCroissants(victimName, userName).toString)
))
}
def all(victimName: String, mbMessage: Option[String], zencroissantURL: String) = {
send(Email(
subject = "Zencroissant a désigné sa nouvelle victime !",
from = "Zencroissants <"+ settings.Mail.contact +">",
to = Seq("All <"+ settings.Mail.all +">"),
bodyHtml = Some(views.html.email.zenall(victimName, mbMessage, zencroissantURL).toString)
))
}
def pression(victimName: String, userName: String, to: String) = {
send(Email(
subject = userName + " vient de te relancer. Tu vas devoir payer tes croissants rapidos.",
from = "Zencroissants <"+ settings.Mail.contact +">",
to = Seq(victimName + " <"+ to +">"),
bodyHtml = Some(views.html.email.pression(victimName, userName).toString)
))
}
def victim(victimName: String, to: String) = {
send(Email(
subject = "Croissify !",
from = "Zencroissants <"+ settings.Mail.contact +">",
to = Seq(victimName + " <"+ to +">"),
bodyHtml = Some(views.html.email.victim(victimName).toString)
))
}
def send(email: Email) = {
if(settings.Mail.mock) {
println(email)
} else {
mailerClient.send(email)
}
}
}
示例7: MailServiceImpl
//设置package包名称以及导入依赖的类
package models.services
import java.util.UUID
import javax.inject.Inject
import controllers.routes
import models.daos.MailTokenDAO
import models.{MailToken, User}
import org.joda.time.DateTime
import views.html.mails
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.libs.mailer.{Email, MailerClient}
import play.api.mvc.RequestHeader
import reactivemongo.api.commands.WriteResult
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class MailServiceImpl @Inject() (
mailerClient: MailerClient,
val messagesApi: MessagesApi,
mailTokenDAO: MailTokenDAO) extends MailService with I18nSupport {
def sendConfirm(user: User)(implicit request: RequestHeader): Future[String] = {
val mailToken = MailToken.create(user, "confirm")
mailTokenDAO.create(mailToken)
val link = routes.SignUpController.mailConfirm(mailToken.id.toString).absoluteURL()
Future(mailerClient.send(confirmMail(user, link)))
}
def confirmMail(user: User, link: String): Email = {
Email(subject = Messages("mail.confirm.title"),
from = Messages("mail.from"),
to = Seq(user.email.getOrElse(throw new Exception("User.email is None."))),
bodyText = Some(mails.welcomeTxt(user.firstName.getOrElse("User.firstname is None."), link).toString),
bodyHtml = Some(mails.welcome(user.firstName.getOrElse("User.firstname is None."), link).toString))
}
def consumeToken(tokenId: UUID, kind: String): Future[Option[UUID]] = {
mailTokenDAO.read(tokenId).map{
case Some(MailToken(dbTokenId, userId, expirationDate, tokenKind)) =>
mailTokenDAO.delete(dbTokenId)
tokenValidation(userId, expirationDate, tokenKind == kind)
case _ => None
}
}
def saveToken(token: MailToken): Future[WriteResult] = mailTokenDAO.create(token)
def tokenValidation(userId: UUID, expirationDate: DateTime, kindMatch: Boolean): Option[UUID] = {
if (expirationDate.isAfterNow && kindMatch) Option(userId) else None
}
}
示例8: EmailerImpl
//设置package包名称以及导入依赖的类
package asynccommunication
import com.google.inject.Inject
import play.api.libs.mailer.{Email, MailerClient}
class EmailerImpl @Inject()(mailerClient: MailerClient) extends Emailer {
override def sendEmail(
subject:String,
from:String,
to:Seq[String],
bodyText:Option[String],
cc:Seq[String] = Seq.empty,
bcc:Seq[String] = Seq.empty):String =
mailerClient.send(Email(subject, from, to, bodyText, None, None, cc, bcc))
}
示例9: TestEmailerImpl
//设置package包名称以及导入依赖的类
package asynccommunication
import com.google.inject.Inject
import play.api.Configuration
import play.api.libs.mailer.{Email, MailerClient}
class TestEmailerImpl @Inject() (mailerClient: MailerClient, configuration:Configuration) extends Emailer {
override def sendEmail(
subject:String,
from:String,
to:Seq[String],
bodyText:Option[String],
cc:Seq[String] = Seq.empty,
bcc:Seq[String] = Seq.empty):String =
mailerClient
.send(
Email(
subject,
from,
Seq(configuration.getString("accessService.testEmailRecipient").getOrElse("")),
bodyText,
None,
None,
cc,
bcc))
}
示例10: SignUpC
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, Singleton}
import play.api.Environment
import play.api.cache.CacheApi
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.mailer.MailerClient
import play.api.mvc._
import configurations.InstagramConfig
import services.SignUpService
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
@Singleton
class SignUpC @Inject()(dbConfigProvider: DatabaseConfigProvider, env: Environment, cache: CacheApi, override implicit val messagesApi: MessagesApi, mailerClient: MailerClient)
extends SignUpService(dbConfigProvider, env, cache, messagesApi, mailerClient: MailerClient)
with InstagramConfig {
def index: Action[AnyContent] = Action.async { implicit req: Request[_] =>
sentMail.flatMap {
case Left(v) => Future successful Ok(views.html.LoginC.login(v))
case Right(_) => Future successful Ok("sent register mail")
}
}
def signUp(hash: String) = Action.async { implicit req: Request[_] =>
doSignUp(hash).flatMap {
case Left(_) => Future successful Ok("expired")
case Right(a) => Future successful Redirect(routes.MyPageC.index().url).withSession(a.session)
}
}
}
示例11: EmailerImpl
//设置package包名称以及导入依赖的类
package communication
import com.google.inject.Inject
import play.api.libs.mailer.{Email, MailerClient}
class EmailerImpl @Inject()(mailerClient: MailerClient) extends Emailer {
override def sendEmail(
subject:String,
from:String,
to:Seq[String],
bodyText:Option[String],
cc:Seq[String] = Seq.empty,
bcc:Seq[String] = Seq.empty):String =
mailerClient.send(Email(subject, from, to, bodyText, None, None, cc, bcc))
}
示例12: TestEmailerImpl
//设置package包名称以及导入依赖的类
package communication
import com.google.inject.Inject
import play.api.Configuration
import play.api.libs.mailer.{MailerClient, Email}
class TestEmailerImpl @Inject() (mailerClient: MailerClient, configuration:Configuration) extends Emailer {
override def sendEmail(
subject:String,
from:String,
to:Seq[String],
bodyText:Option[String],
cc:Seq[String] = Seq.empty,
bcc:Seq[String] = Seq.empty):String =
mailerClient
.send(
Email(
subject,
from,
Seq(configuration.getString("crauth.testEmailRecipient").getOrElse("")),
bodyText,
None,
None,
cc,
bcc))
}