All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skinny.mailer.SkinnyMailerConfigApi.scala Maven / Gradle / Ivy

There is a newer version: 2.5.2
Show newest version
package skinny.mailer

import com.typesafe.config.Config

/**
 * Configuration for SkinnyMailer.
 */
trait SkinnyMailerConfigApi extends SkinnyMailerConfigBase {

  def toCaseClass: SkinnyMailerConfig = SkinnyMailerConfig(
    debug = this.debug,
    mimeVersion = this.mimeVersion,
    charset = this.charset,
    contentType = this.contentType,
    defaultFrom = this.defaultFrom,
    transportProtocol = this.transportProtocol,
    smtp = this.smtp.toCaseClass
  )

  /**
   * Debug mode if true.
   */
  def debug: Boolean = loadedConfig.flatMap(c => Option(c.getBoolean("debug"))).getOrElse(false)

  /**
   * MIME version.
   */
  def mimeVersion: String = loadedConfig.flatMap(c => Option(c.getString("mimeVersion"))).getOrElse("1.0")

  /**
   * Charset.
   */
  def charset: String = loadedConfig.flatMap(c => Option(c.getString("charset"))).getOrElse("UTF-8")

  /**
   * Content-Type header (default: text/plain)
   */
  def contentType: String = loadedConfig.flatMap(c => Option(c.getString("contentType"))).getOrElse("text/plain")

  /**
   * From header default value.
   */
  def defaultFrom: Option[String] = loadedConfig.flatMap(c => Option(c.getString("from")))

  /**
   * Transport protocol.
   */
  def transportProtocol: String = loadedConfig.flatMap(c => Option(c.getString("transport.protocol"))).getOrElse("logging")

  // refs self
  private val self: SkinnyMailerConfigApi = this

  /**
   * SMTP configuration.
   */
  val smtp: SkinnyMailerSmtpConfigApi = new SkinnyMailerSmtpConfigApi {
    override def name: String = self.name
    override def skinnyEnv: String = self.skinnyEnv
    override lazy val loadedConfig: Option[Config] = self.loadedConfig
  }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy