当前位置: 首页>>代码示例>>Scala>>正文


Scala Email类代码示例

本文整理汇总了Scala中play.api.libs.mailer.Email的典型用法代码示例。如果您正苦于以下问题:Scala Email类的具体用法?Scala Email怎么用?Scala Email使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Email类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: sendMail

//设置package包名称以及导入依赖的类
package controllers

import org.intracer.wmua.User
import play.api.libs.mailer.{Email, MailerPlugin}

trait SendMail {
  def sendMail(from: User, to: User, subject: String, message: String)
}

class SendMailSMTP extends SendMail {

  override def sendMail(fromUser: User, toUser: User, subject: String, message: String) = {
    val email = Email(
      from = s"${fromUser.fullname} <${fromUser.email}>",
      to = Seq(toUser.email),
      subject = subject,
      bodyText = Some(message)
    )
    MailerPlugin.send(email)(play.api.Play.current)
  }
} 
开发者ID:intracer,项目名称:wlxjury,代码行数:22,代码来源:SendMail.scala

示例2: 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)
        }
      }
    }
  }
} 
开发者ID:serversideapps,项目名称:silhmojs,代码行数:58,代码来源:ForgotPasswordController.scala

示例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))
  }
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:42,代码来源:MailerUtils.scala

示例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)
  }

} 
开发者ID:chinhnk00494,项目名称:cw-CMR,代码行数:52,代码来源:EmailUtil.scala

示例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")
    }
  }

} 
开发者ID:bananapianist,项目名称:playfw_sample,代码行数:40,代码来源:MailsendActor.scala

示例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)
    }
  }
} 
开发者ID:denis-mludek,项目名称:zencroissants,代码行数:54,代码来源:Mailer.scala

示例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
  }

} 
开发者ID:Biacco42,项目名称:play-silhouette-mail-confirm-seed,代码行数:56,代码来源:MailServiceImpl.scala

示例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))


} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:19,代码来源:EmailerImpl.scala

示例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))

} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:29,代码来源:TestEmailerImpl.scala

示例10: 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))


} 
开发者ID:shafiquejamal,项目名称:play-authentication,代码行数:19,代码来源:EmailerImpl.scala

示例11: 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))

} 
开发者ID:shafiquejamal,项目名称:play-authentication,代码行数:29,代码来源:TestEmailerImpl.scala


注:本文中的play.api.libs.mailer.Email类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。