Learn R Programming

lgrExtra (version 0.1.0)

AppenderSendmail: Send emails via sendmailR

Description

Send mails via sendmailR::sendmail(), which requires that you have access to an SMTP server that does not require authentication. This Appender keeps an in-memory buffer like lgr::AppenderBuffer. If the buffer is flushed, usually because an event of specified magnitude is encountered, all buffered events are concatenated to a single message. The default behavior is to push the last 30 log events in case a fatal event is encountered.

Arguments

Value

The $new() method returns an R6::R6 that inherits from lgr::Appender and can be uses as an appender by a lgr::Logger.

Super classes

lgr::Filterable -> lgr::Appender -> lgr::AppenderMemory -> lgrExtra::AppenderDigest -> lgrExtra::AppenderMail -> AppenderSendmail

Active bindings

control

see sendmailR::sendmail()

headers

see sendmailR::sendmail()

Methods

Inherited methods


Method new()

see AppenderMail for details

Usage

AppenderSendmail$new(
  to,
  control,
  threshold = NA_integer_,
  flush_threshold = "fatal",
  layout = LayoutFormat$new(fmt = "   %L [%t] %m %f", timestamp_fmt = "%H:%M:%S"),
  subject_layout = LayoutFormat$new(fmt = "[LGR] %L: %m"),
  buffer_size = 29,
  from = get_user(),
  cc = NULL,
  bcc = NULL,
  html = FALSE,
  headers = NULL,
  filters = NULL
)


Method flush()

Usage

AppenderSendmail$flush()


Method set_control()

Usage

AppenderSendmail$set_control(x)


Method set_headers()

Usage

AppenderSendmail$set_headers(x)

See Also

lgr::LayoutFormat, lgr::LayoutGlue

Other Appenders: AppenderAWSCloudWatchLog, AppenderDbi, AppenderDt, AppenderDynatrace, AppenderElasticSearch, AppenderGmail, AppenderPool, AppenderPushbullet, AppenderSyslog

Other Digest Appenders: AppenderDigest, AppenderMail, AppenderPushbullet

Examples

Run this code
if (FALSE) {
lgr::AppenderSendmail$new(
  to = "user@ecorp.com",
  control = list(smtpServer = "mail.ecorp.com"),
  from = "lgr_user@yourmail.com"
)
}

if (requireNamespace("sendmailR")){
# requires that you have access to an SMTP server

  lg <- lgr::get_logger("lgrExtra/test/mail")$
    set_propagate(FALSE)$
    add_appender(AppenderSendmail$new(
      from = "ceo@ecorp.com",
      to = "some.guy@ecorp.com",
    control = list(smtpServer = "mail.somesmptserver.com")
  ))
  # cleanup
  invisible(lg$config(NULL))
}

Run the code above in your browser using DataLab