Skip to content

Instantly share code, notes, and snippets.

@jimbrig
Created June 3, 2020 15:54
Show Gist options
  • Save jimbrig/964b0bd05c8e736bcb1d95cc4ca1f9d7 to your computer and use it in GitHub Desktop.
Save jimbrig/964b0bd05c8e736bcb1d95cc4ca1f9d7 to your computer and use it in GitHub Desktop.
# ------------------------------------------------------------------------
#
# Title : Emailing with RDCOMClient Walkthrough Script
# By : Jimmy Briggs <jimmy.briggs@oliverwyman.com>
# Date : 2020-06-03
#
# ------------------------------------------------------------------------
# install RDCOMClient package:
# Run the following to install the stable version from CRAN:
install.packages("RDCOMClient")
# or from the Omegahat repository
install.packages("RDCOMClient", repos = "http://www.omegahat.net/R")
# Alternatively, you can build the package from source without much difficulty.
# With Rtools installed, one can build the package from source without the need
# for any third-party libraries.
# From the (Windows) command line
# R CMD INSTALL RDCOMClient
# or using devtools
devtools::install_github("omegahat/RDCOMClient")
# ---------------------------------------------------------------------------
library(RDCOMClient)
# initialize email via command line:
OutApp <- COMCreate("Outlook.Application")
outMail <- OutApp$CreateItem(0)
# fill in adressee(s), subject, and body
outMail[["To"]] = "<email_address>"
outMail[["subject"]] = "<email subject>"
outMail[["body"]] = "<email_body>"
# add an attachment:
outMail[["Attachments"]]$Add("<email_attached_file>")
# send
outMail$Send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment