• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala InternetAddress类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Mailer

//设置package包名称以及导入依赖的类
package org.kirhgoff.lastobot

import java.util.Properties
import javax.mail.{Message, Session}
import javax.mail.internet.{InternetAddress, MimeMessage}

import scala.io.Source


object Mailer {
  val host = "smtp.gmail.com"
  val port = "587"

  val address = "[email protected]"
  val username = "lastobot"
  val password = Source.fromFile(System.getProperty("user.home")
    + "/.lastobot/.mail").getLines.mkString

  def sendMail(text:String, subject:String) = {
    val properties = new Properties()
    properties.put("mail.smtp.port", port)
    properties.put("mail.smtp.auth", "true")
    properties.put("mail.smtp.starttls.enable", "true")

    val session = Session.getDefaultInstance(properties, null)
    val message = new MimeMessage(session)
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(address));
    message.setSubject(subject)
    message.setContent(text, "text/html")

    val transport = session.getTransport("smtp")
    transport.connect(host, username, password)
    transport.sendMessage(message, message.getAllRecipients)
  }

  def main(args:Array[String]) = {
    sendMail("aaaa", "bbb")
  }
} 
开发者ID:kirhgoff,项目名称:lastobot,代码行数:40,代码来源:Mailer.scala


示例2: EMail

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

import javax.mail.internet.{InternetAddress, MimeMessage}
import javax.mail._
import javax.mail._
import java.util.Date


class EMail(email: String, password: String, smtp: String) {
  val session = getSession
  def sendMail(address:String,title:String,body:String)={
    try{
      val msg = new MimeMessage(session)
      msg.setFrom(new InternetAddress(email))
      msg.setRecipients(Message.RecipientType.TO, address)
      msg.setSubject(title)
      msg.setSentDate(new Date())
      if (body.contains("<") && body.contains(">")) {
        msg.setContent(body, "text/html;charset=utf-8")
      } else {
        msg.setText(body)
      }
      Transport.send(msg)
      true
    }catch {
      case th:Throwable=>th.printStackTrace()
        false
    }
  }

  private def getSession() = {
    val SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"
    val props = System.getProperties()
    props.setProperty("mail.smtp.host", smtp)
    props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY)
    props.setProperty("mail.smtp.socketFactory.fallback", "false")
    props.setProperty("mail.smtp.port", "465")
    props.setProperty("mail.smtp.socketFactory.port", "465")
    props.put("mail.smtp.auth", "true")
    val ah = new Authenticator() {
      override protected def getPasswordAuthentication(): PasswordAuthentication = {
          new PasswordAuthentication(email, password)
      }
    }
    Session.getDefaultInstance(props, ah)
  }

} 
开发者ID:livehl,项目名称:paipai,代码行数:49,代码来源:EMail.scala


示例3: EmailTarget

//设置package包名称以及导入依赖的类
package lert.core.rule.target

import java.util.Properties
import javax.inject.Inject
import javax.mail._
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage

import lert.core.config.ConfigProvider
import lert.core.utils.JavaUtils
import com.typesafe.scalalogging.LazyLogging

class EmailTarget @Inject()(configProvider: ConfigProvider) extends LazyLogging {
  def send(recipient: String, subject: String, body: String): Unit = {
    val config = configProvider.config
    require(config.targetSettings != null, "Email server settings are not specified")

    val properties = JavaUtils.toProperties(Map(
      "mail.smtp.host" -> config.targetSettings.mailServer.host,
      "mail.smtp.port" -> config.targetSettings.mailServer.port.toString,
      "mail.smtp.user" -> config.targetSettings.mailServer.username,
      "mail.smtp.password" -> config.targetSettings.mailServer.password,
      "mail.smtp.auth" -> Option(config.targetSettings.mailServer.auth).map(_.toString).orNull,
      "mail.smtp.starttls.enable" -> "true",
      "mail.smtp.socketFactory.class" -> "javax.net.ssl.SSLSocketFactory",
      "mail.smtp.socketFactory.port" -> config.targetSettings.mailServer.port.toString
    ))

    val session = Option(config.targetSettings.mailServer.password)
      .map(p => Session.getDefaultInstance(properties, new Authenticator {
        override def getPasswordAuthentication(): PasswordAuthentication =
          new PasswordAuthentication(config.targetSettings.mailServer.username, p)
      })).getOrElse(Session.getDefaultInstance(properties))

    val message = new MimeMessage(session)
    message.setFrom(new InternetAddress(config.targetSettings.mailServer.username))
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient))
    message.setSubject(subject)
    message.setText(body)
    Transport.send(message)
  }

  class SMTPAuthenticator extends Authenticator {
    def getPasswordAuthentication(mail: String, password: String) = new PasswordAuthentication(mail, password)
  }

} 
开发者ID:l3rt,项目名称:l3rt,代码行数:48,代码来源:EmailTarget.scala


示例4: EmailRequestInfo

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.iomodels

import javax.mail.internet.InternetAddress

import com.fasterxml.jackson.annotation.JsonProperty

case class EmailRequestInfo(@JsonProperty(required = false) appName: String,
                            @JsonProperty(required = false) to: Set[EmailAddress] = Set.empty[EmailAddress],
                            @JsonProperty(required = false) cc: Set[EmailAddress] = Set.empty[EmailAddress],
                            @JsonProperty(required = false) bcc: Set[EmailAddress] = Set.empty[EmailAddress],
                            @JsonProperty(required = false) from: EmailAddress,
                            @JsonProperty(required = false) replyTo: EmailAddress

                           ) extends ChannelRequestInfo {
  def toStrict:EmailRequestInfo = {
    this.copy(appName = appName.toLowerCase, cc = Option(cc).getOrElse(Set.empty), bcc = Option(bcc).getOrElse(Set.empty) )
  }
}

case class EmailAddress(name: String, address: String){
  def toInternetAddress:InternetAddress = {
    new InternetAddress(address,name)
  }
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:25,代码来源:EmailRequestInfo.scala


示例5: apply

//设置package包名称以及导入依赖的类
// Copyright (C) 2017 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.model

import javax.mail.internet.{InternetAddress, MimeBodyPart, MimeMultipart}



  def apply(from: InternetAddress, to: InternetAddress, subject: String, text: String): Email = {
    new Email(from, to, subject, {
      val m = new MimeBodyPart()
      m.setContent(text,"text/plain")
//      m.setText(text)
      m
    })
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:17,代码来源:Email.scala


示例6: GensonConfig

//设置package包名称以及导入依赖的类
// Copyright (C) 2017 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.service

import javax.mail.internet.InternetAddress

import com.owlike.genson._
import com.owlike.genson.stream.{ObjectReader, ObjectWriter}

object GensonConfig {
  val genson = new GensonBuilder().
    useIndentation(true).
    useRuntimeType(true).
    useDateAsTimestamp(true).
    withConverters(new InternetAddressConverter).
    withBundle(ScalaBundle().useOnlyConstructorFields(false)).
    create()
}

class InternetAddressConverter extends Converter[InternetAddress] {
  override def serialize(ia: InternetAddress, writer: ObjectWriter, ctx: Context): Unit = {
    writer.writeValue(ia.toString)
  }

  override def deserialize(reader: ObjectReader, ctx: Context): InternetAddress = {
    new InternetAddress(reader.valueAsString())
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:28,代码来源:GensonConfig.scala


示例7: JsonTests

//设置package包名称以及导入依赖的类
// Copyright (C) 2017 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.model

import javax.mail.internet.InternetAddress

import com.grierforensics.danesmimeatoolset.service.EmailSender
import com.grierforensics.danesmimeatoolset.service.GensonConfig.genson
import org.scalatest.{BeforeAndAfterAll, FunSuite}

class JsonTests extends FunSuite with BeforeAndAfterAll {
  val message = EmailSender.createMessage(Email(new InternetAddress("[email protected]"), new InternetAddress("[email protected]"), "subject", "body"))

  test("json InternetAddress (problem class)") {
    val ia1: InternetAddress = new InternetAddress("[email protected]", "Bob")
    val j1: String = genson.serialize(ia1)
    println(j1)
    val ia2: InternetAddress = genson.deserialize(j1, classOf[InternetAddress])
    assert(ia1 == ia2)
  }

  test("json serialization") {
    val w1 = new Workflow("[email protected]")
    w1.updateCert()
    w1.handleMessage(message)

    val j1: String = genson.serialize(w1)
    println(j1)
    //val w2: Workflow = genson.deserialize(j1,classOf[Workflow])
    //assert(w1===w2)
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:32,代码来源:JsonTests.scala


示例8: DstTestValues

//设置package包名称以及导入依赖的类
// Copyright (C) 2016 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.util

import javax.mail.internet.InternetAddress

import com.grierforensics.danesmimeatoolset.TestDaneSmimeaService
import com.grierforensics.danesmimeatoolset.service.Context
import com.grierforensics.danesmimeatoolset.util.ConfigHolder._
import org.bouncycastle.pkix.jcajce.JcaPKIXIdentity

object DstTestValues {

  val testDss = new TestDaneSmimeaService

  val emailWithoutDane = "[email protected]"

  val emailWithDane = "[email protected]"
  val emailWithDanePublishedZoneLine = """2043fd2443778d1a3b9aa1688d2fb1749da1c80b2ac60368600e1c41._smimecert.had-pilot.biz. IN TYPE53 \# 1058 0300003082041B30820303A003020102020900B1F478FC6480FE7C300D06092A864886F70D01010505003081A3310B3009060355040613025553310E300C06035504080C0553746174653115301306035504070C0C44656661756C74204369747931123010060355040A0C0944414E4520546573743111300F060355040B0C0864616E6574657374311F301D06035504030C1664616E6574657374406861642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A301E170D3135303132323139353231355A170D3135303232313139353231355A3081A3310B3009060355040613025553310E300C06035504080C0553746174653115301306035504070C0C44656661756C74204369747931123010060355040A0C0944414E4520546573743111300F060355040B0C0864616E6574657374311F301D06035504030C1664616E6574657374406861642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A30820122300D06092A864886F70D01010105000382010F003082010A028201010096CA3B7C2610F79F40318BD616737C5D70A5F2B806795E8CDF5A69491AD78060A3501F364CDC3A61C491126AE21EA00D973B0C4D9DE635C1A844BDF5AEF662310E848C1F03456553BFBAB2EF04917DC9C5C24FC2217EC590B958EC83887A6AF239A00A38F1F1E4CB7814D49CCFA36977C2E77239E79759D79A3D7A448E462414C73DE88CDEF61133B0087297AEB39761E7270A8292C711A404D258614DC58489D74BF1BADC5DF0C8472086B3C3F828D947B96C48149E59C47A1833F13A4FBB31E91D34F0AEA51A100F982219E7447D94AF0DA0DB811B41E1933367EF11618E0318C2EC29ACE0206FF943973F694A8F05B8E11F414F00A0FBCD7C2511BA13A3750203010001A350304E301D0603551D0E0416041424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B301F0603551D2304183016801424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B300C0603551D13040530030101FF300D06092A864886F70D010105050003820101001497E04E8629172C3B545693F3C0C8F2B567CA573C6A6AFD2788B001DC4CEDD87538E8F2EFFF4FDB9F2FBDE43FFC1EBBD32A247138741D2266E146585C77D262F0278E3D860CEAAE44570B81D069D4B893496B61751BA996B6A461B456F63A8FAB51ACEC63897DFFA5B106823E90917CD6247867C206B09E4606390223A100F7F2746B9128FB8E187533F272F1347CCAF4B1E6A16F408816855FBCCE2575193A8121CC68378F4A8A8F82144A27E1D78B7FEE66D6FD63D91A23D2C1CF0811A16B839655B6A0020287C7AA0B1BF97AD4469AE83E8649FFF6C622DD3FB5D9FCAE064EDCE2DFD7F0ADE6AEFC106557B436D9A518F47ED8961622E16A96115E393619"""
  val emailWithDaneCertHex = "3082041B30820303A003020102020900B1F478FC6480FE7C300D06092A864886F70D01010505003081A3310B3009060355040613025553310E300C06035504080C0553746174653115301306035504070C0C44656661756C74204369747931123010060355040A0C0944414E4520546573743111300F060355040B0C0864616E6574657374311F301D06035504030C1664616E6574657374406861642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A301E170D3135303132323139353231355A170D3135303232313139353231355A3081A3310B3009060355040613025553310E300C06035504080C0553746174653115301306035504070C0C44656661756C74204369747931123010060355040A0C0944414E4520546573743111300F060355040B0C0864616E6574657374311F301D06035504030C1664616E6574657374406861642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A30820122300D06092A864886F70D01010105000382010F003082010A028201010096CA3B7C2610F79F40318BD616737C5D70A5F2B806795E8CDF5A69491AD78060A3501F364CDC3A61C491126AE21EA00D973B0C4D9DE635C1A844BDF5AEF662310E848C1F03456553BFBAB2EF04917DC9C5C24FC2217EC590B958EC83887A6AF239A00A38F1F1E4CB7814D49CCFA36977C2E77239E79759D79A3D7A448E462414C73DE88CDEF61133B0087297AEB39761E7270A8292C711A404D258614DC58489D74BF1BADC5DF0C8472086B3C3F828D947B96C48149E59C47A1833F13A4FBB31E91D34F0AEA51A100F982219E7447D94AF0DA0DB811B41E1933367EF11618E0318C2EC29ACE0206FF943973F694A8F05B8E11F414F00A0FBCD7C2511BA13A3750203010001A350304E301D0603551D0E0416041424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B301F0603551D2304183016801424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B300C0603551D13040530030101FF300D06092A864886F70D010105050003820101001497E04E8629172C3B545693F3C0C8F2B567CA573C6A6AFD2788B001DC4CEDD87538E8F2EFFF4FDB9F2FBDE43FFC1EBBD32A247138741D2266E146585C77D262F0278E3D860CEAAE44570B81D069D4B893496B61751BA996B6A461B456F63A8FAB51ACEC63897DFFA5B106823E90917CD6247867C206B09E4606390223A100F7F2746B9128FB8E187533F272F1347CCAF4B1E6A16F408816855FBCCE2575193A8121CC68378F4A8A8F82144A27E1D78B7FEE66D6FD63D91A23D2C1CF0811A16B839655B6A0020287C7AA0B1BF97AD4469AE83E8649FFF6C622DD3FB5D9FCAE064EDCE2DFD7F0ADE6AEFC106557B436D9A518F47ED8961622E16A96115E393619"

  val dstAddress = Context.dstAddress
  val dstIdentity = Context.dstIdentity
  val testAddress: InternetAddress = dstAddress
  val testIdentity: JcaPKIXIdentity = dstIdentity

  val bobAddress: InternetAddress = new InternetAddress("[email protected]", "Bob")
  val bobIdentity: JcaPKIXIdentity = IdentityUtil.generateIdentity(bobAddress)
//  val bobPopHost: String = "pop.gmail.com"
//  val bobEmailPassword: String = "dst.bob!"

  val aliceAddress: InternetAddress = new InternetAddress("[email protected]", "Alice")
  val aliceIdentity: JcaPKIXIdentity = IdentityUtil.generateIdentity(aliceAddress)

  val badCertHex = "F70D010100B1F478FC6480FE7C300D06092A86488603081A3310B3009060355040613025553310E30050503082041B30820303A0030201020209015301306035504070C0C446566617560F060355040B0C0864616E6574657374311F3010A0C0944414E452054657374311130D06035504030C1664616E657465737440686110060355040642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A301E170D3135303132323139353231355A170D3135303232313139353231355A3081A3310B3009060355040613025553310E300C06035504080C0553746174653115301306035504070C0C44656661756C74204369747931123010060355040A0C0944414E4520546573743111300F060355040B0C0864616E6574657374311F301D06035504030C1664616E6574657374406861642D70696C6F742E62697A3125302306092A864886F70D010901161664616E6574657374406861642D70696C6F742E62697A30820122300D06092A864886F70D01010105000382010F003082010A028201010096CA3B7C2610F79F40318BD616737C5D70A5F2B806795E8CDF5A69491AD78060A3501F364CDC3A61C491126AE21EA00D973B0C4D9DE635C1A844BDF5AEF662310E848C1F03456553BFBAB2EF04917DC9C5C24FC2217EC590B958EC83887A6AF239A00A38F1F1E4CB7814D49CCFA36977C2E77239E79759D79A3D7A448E462414C73DE88CDEF6113374BF1BADC5DF0C8472086B3C3F828D947B96C48149E59C47A1833F13A4FBB31E91D34F0AEA51A100F982219E7447D94AF0DA0DB811B41E1933367EF11618E0318C2EC29ACE0206FF943973F69B0087297AEB39761E7270A8292C711A404D258614DC58489D13A3750203010001A350304E301D0603551D0E0416041424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B301F0603551D2304183016801424C50BBBEE31C6AD9A7AEC845BD0CC435FF4FA2B300C0603551D13040530030101FF300D06092A864886F70D010105050003820101001497E04E8629172C3B545693F3C0C8F2B567CA573C6A6AFD2788B001DC4CEDD87538E8F2EFFF4FDB9F2FBDE43FFC1EBBD32A247138741D2266E146585C77D262F0278E3D860CEAAE44570B81D069D4B893496B61751BA996B6A461B456F63A8FAB51ACEC63897DFFA5B106823E90917CD6247867C206B09E4606390223A100F7F2746B9128FB8E187533F272F1347CCAF4B1E6A16F408816855FBCCE2575193A8121CC68378F4A8A8F82144A27E1D78B7FEE66D6FD63D91A23D2C1CF0811A16B839655B6A0020287C7AA0B1BF97AD4469AE83E8649FFF6C622DD3FB5D9FCAE064EDCE2DFD7F0ADE6AEFC106557B436D9A518F47ED8961622E16A96115E393619"
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:36,代码来源:DstTestValues.scala


示例9: send

//设置package包名称以及导入依赖的类
package com.github.cuzfrog.maila.server

import java.util.Date
import javax.mail.Message.RecipientType
import javax.mail.internet.{InternetAddress, MimeMessage}
import javax.mail.{Address, MessagingException, Session, Transport}

private[server] trait Sender {
  def send(recipients: Seq[String], subject: String, text: String): (Boolean, String)

  def close(): Unit
}

private[server] object Sender {
  def apply(session: Session, transport: Transport, user: String): Sender = new JmSender(session, transport, user)

  private class JmSender(session: Session, transport: Transport, user: String) extends Sender {

    def send(recipients: Seq[String], subject: String, text: String): (Boolean, String) = {
      val addresses: Array[Address] = recipients.map(new InternetAddress(_)).toArray
      val message = new MimeMessage(session)
      message.setFrom(new InternetAddress(user))

      message.addRecipients(RecipientType.TO, addresses)
      message.setSubject(subject)
      message.setText(text)
      message.setSentDate(new Date())
      val msg = s"Sent message[${message.getSubject}] to[${message.getAllRecipients.mkString(",")}]"
      try {
        transport.sendMessage(message, message.getAllRecipients)
        (true, s"$msg successfully.")
      } catch {
        case e: MessagingException =>
          (false, s"$msg Failed with msg:${e.getMessage}")
      }
    }

    def close(): Unit = transport.close()
  }

} 
开发者ID:cuzfrog,项目名称:maila,代码行数:42,代码来源:Sender.scala


示例10: SimpleMessage

//设置package包名称以及导入依赖的类
package com.twitter.diffy.util

import com.twitter.logging.Logger
import com.twitter.util.{FuturePool, Future}

import javax.mail._
import javax.mail.internet.{InternetAddress, MimeMessage}
import java.util.Properties

case class SimpleMessage(
  from: String,
  to: String,
  bcc: String,
  subject: String,
  body: String)

class EmailSender(log: Logger, send: MimeMessage => Unit = Transport.send) {
  private[this] val props = new Properties
  props.put("mail.smtp.host", "smtp-gw1.wal-mart.com")
  props.put("mail.smtp.auth", "false")
  props.put("mail.smtp.port", "25")

  private[this] val session = Session.getDefaultInstance(props, null)

  def apply(msg: SimpleMessage): Future[Unit] =
    FuturePool.unboundedPool {
      val message = new MimeMessage(session)
      message.setFrom(new InternetAddress(msg.from))
      message.setRecipients(
        Message.RecipientType.TO,
        InternetAddress.parse(msg.to) map { _.asInstanceOf[Address]}
      )
      message.addRecipients(
        Message.RecipientType.BCC,
        InternetAddress.parse(msg.bcc) map { _.asInstanceOf[Address]}
      )
      message.setSubject(msg.subject)
      message.setContent(msg.body, "text/html; charset=utf-8")
      try {
        send(message)
      } catch { case e =>
        log.error(e, "failed to send message")
      }
    }
} 
开发者ID:sachinmanchanda,项目名称:diffy_unicast,代码行数:46,代码来源:EmailSender.scala


示例11: MailRecipient

//设置package包名称以及导入依赖的类
package io.scalac.newspaper.mailer.outbound

import javax.mail.internet.InternetAddress

import scala.concurrent.Future
import scala.util.Failure

case class MailRecipient(to: String) extends AnyVal

case object MailSent

trait MailSender {
  def send(to: MailRecipient, mailContent: String): Future[MailSent.type]
}

class LogSender() extends MailSender {
  override def send(to: MailRecipient, mailContent: String) = {
    println(s"[FAKE][SENDING to: ${to.to}] $mailContent")
    Future.successful(MailSent)
  }
}

case class MailerConf(host: String, port: Int, user: String, password: String)

class SmtpMailSender(conf: MailerConf) extends MailSender {
  import courier._
  import Defaults._

  val mailer = Mailer(conf.host, conf.port)
    .auth(true)
    .as(conf.user, conf.password)
    .startTtls(true)()

  override def send(to: MailRecipient, mailContent: String): Future[MailSent.type] = {
    println(s"[SENDING to: ${to.to}] $mailContent")
    val msg = Envelope.from(new InternetAddress(conf.user))
      .to(new InternetAddress(to.to))
      .subject("Newspaper!")
      .content(Text(mailContent))

    val sendingF = mailer(msg).map(_ => MailSent)

    sendingF.onComplete {
      case Failure(ex) =>
        println(s"Message NOT delivered to ${to} due to $ex")
        println(s"--- ${ex.getStackTrace.mkString("\n  ")}")
      case _ =>
        println(s"Message was delivered to ${to}!")
    }

    sendingF
  }
} 
开发者ID:ScalaConsultants,项目名称:newspaper,代码行数:54,代码来源:MailSender.scala


示例12: Email

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

import java.util.Properties
import javax.mail.Message.RecipientType
import javax.mail.internet.{InternetAddress, MimeMessage}
import javax.mail._

object Email {
  def apply(userName: String, password: String): Email = new Email(userName, password)
}

class Email(userName: String, password: String) {
  private val session = getSession

  def getSession: Session = {
    val props: Properties = new Properties()
    props.put("mail.smtp.host", "smtp.gmail.com")
    props.put("mail.smtp.socketFactory.port", "465")
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory")
    props.put("mail.smtp.auth", "true")
    props.put("mail.smtp.port", "465")

    val authenticator: Authenticator = new Authenticator {
      override def getPasswordAuthentication: PasswordAuthentication = new PasswordAuthentication(userName, password)
    }
    Session.getDefaultInstance(props, authenticator)
  }


  def send(to: List[String], subject: String, body: String): Either[String, Unit] = {
    val message: MimeMessage = new MimeMessage(session)
    try {

      message.setFrom(new InternetAddress("[email protected]", "Asana Weekly"))
      message.setReplyTo(Array(new InternetAddress("[email protected]")))
      message.setSubject(subject)
      message.setContent(body, "text/html; charset=utf-8")

      to.foreach(message.addRecipients(RecipientType.BCC, _))
      Right(Transport.send(message))
    } catch {
      case e: Exception => Left(e.getMessage)
    }
  }
} 
开发者ID:hhimanshu,项目名称:asanaweeklyreport,代码行数:46,代码来源:Email.scala


示例13: Mail

//设置package包名称以及导入依赖的类
package models.Entity

import javax.mail.internet.InternetAddress

import org.joda.time.DateTime


case class Mail(
                 from: InternetAddress
                 , tos         : Seq[InternetAddress]
                 , ccs         : Seq[InternetAddress]
                 , bccs        : Seq[InternetAddress]
                 , subject     : String
                 , sentDate    : DateTime
                 , plainBody   : Option[String]
                 , htmlBody    : Option[String]
                 , attachments : Seq[MailAttachment]
                 , error       : Option[String])

case class MailAttachment(cid: String, attach: Array[Byte], extension : String) 
开发者ID:ShotaOda,项目名称:scala-slick-backbone,代码行数:21,代码来源:Mail.scala


示例14: sendMail

//设置package包名称以及导入依赖的类
package wuxi99
import javax.mail.Message
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
import java.util.Date
import java.util.Properties
import grizzled.slf4j.Logger
trait Email {
	def sendMail(mailTitle:String,mailContent:String)
	def sendMailFL(mailTitle:String,fileName:String,line:Int,AppCount:Int){
		val mailContent = s"""<b>??:${fileName}</b><br>
			<b>??:${line}</b><br>
			<b>???:${AppCount}</b>"""
		sendMail(mailTitle,mailContent)
	}
 def sendMailHtml(mailTitle:String,mailContent:String){
    val mailContentHtml = s"<b>${mailContent}</b>"
    sendMail(mailTitle,mailContentHtml)
  }
}

object MailUtility extends Email {
	private val smtpServer = "smtp.exmail.qq.com"
	private val fromMail = "[email protected]"
	private val toMail = "[email protected]"
	private val user = fromMail
	private val password = "ys123456"
	@transient lazy val logger = Logger[this.type]


	def sendMail(mailTitle:String,mailContent:String) {
	  try {	
		val props = new Properties()
		props.put("mail.smtp.host",smtpServer )
		props.put("mail.smtp.auth", "true")
		val session = Session.getInstance(props)

		val message = new MimeMessage(session)
		message.setFrom(new InternetAddress(fromMail))
		message.setRecipient(Message.RecipientType.TO, new InternetAddress(toMail))
		message.setSubject(mailTitle)
		message.setContent(mailContent, "text/html;charset=utf-8")
		//message.setText(mailContent)
		message.setSentDate(new Date())
		message.saveChanges()

		val transport = session.getTransport("smtp")
		transport.connect(user, password)
		transport.sendMessage(message, message.getAllRecipients())
		transport.close()
	  } catch {
		case _ : Throwable => logger.info("This Mail Didnot Send:[ " + mailTitle + " ] [ " + mailContent + "]" )
          }	
	}

} 
开发者ID:yangshuxuan,项目名称:OptFoatSalesWithSparkAndScala,代码行数:59,代码来源:mailUtility.scala


示例15: EmailSender

//设置package包名称以及导入依赖的类
package actors.helpers

import javax.mail._
import javax.mail.internet.{InternetAddress, MimeMessage}

import model.b2c.Flat
import play.api.Configuration


class EmailSender (configuration: Configuration) {

  val localizationHelper = new LocalizationHelper

  val props = new java.util.Properties()
  props.put(EmailSender.SmtpPropStartTls, "true")
  props.put(EmailSender.SmtpPropSmtpAuth, "true")
  props.put(EmailSender.SmtpPropSmtpHost, configuration.get[String](EmailSender.SmtpHost))
  props.put(EmailSender.SmtpPropSmtpPort, configuration.get[String](EmailSender.SmtpPort))
  val session = Session.getInstance(props,
    new javax.mail.Authenticator() {
      override protected def getPasswordAuthentication(): javax.mail.PasswordAuthentication = {
        return new PasswordAuthentication(configuration.get[String](EmailSender.SmtpUsername),
          configuration.get[String](EmailSender.SmtpPassword))
      }
    });

  def sendEmail(flat: Flat) = {
    val message = new MimeMessage(session)
    message.setText(views.html.Application.notification
      .render(flat,localizationHelper.getMessages(Language.EN))
      .body,"utf-8", "html")
    message.setFrom(new InternetAddress(configuration.get[String](EmailSender.SentFrom)))
    message.setSubject(flat.address.get+ ", "+flat.district.get+", "+flat.city.get+", " +flat.price.get+ " EUR")
    message.setRecipients(Message.RecipientType.TO,
      configuration.get[String](EmailSender.SendToList).split(",")
        .map(email => {
          val address: Address = new InternetAddress(email)
          address
        }
        ).array
    )
    Transport.send(message)
  }
}

object EmailSender {
  val SmtpHost = "smtp.host"
  val SmtpPort = "smtp.port"
  val SmtpUsername = "smtp.username"
  val SmtpPassword = "smtp.password"
  val SendToList = "smtp.sendto"
  val SentFrom = "smtp.sentfrom"
  val SmtpPropStartTls = "mail.smtp.starttls.enable"
  val SmtpPropSmtpAuth = "mail.smtp.auth"
  val SmtpPropSmtpHost = "mail.smtp.host"
  val SmtpPropSmtpPort = "mail.smtp.port"
} 
开发者ID:oginskis,项目名称:play-vo-flats,代码行数:58,代码来源:EmailSender.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Log类代码示例发布时间:2022-05-23
下一篇:
Scala State类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap