Title: | A Certe R Package for Automated Mailing |
---|---|
Description: | A Certe R Package for working remotely with emails, using Microsoft 365. This package is part of the 'certedata' universe. |
Authors: | Matthijs S. Berends [aut, cre], Erwin E. A. Hassing [aut], Certe Medical Diagnostics & Advice Foundation [cph, fnd] |
Maintainer: | Matthijs S. Berends <[email protected]> |
License: | GPL-2 |
Version: | 1.7.5 |
Built: | 2024-11-20 05:51:33 UTC |
Source: | https://github.com/certe-medical-epidemiology/certemail |
After connecting using connect_outlook()
, the get_*()
functions retrieve properties from this connection.
get_name(account = connect_outlook()) get_department(account = connect_outlook()) get_address(account = connect_outlook()) get_phone_numbers(account = connect_outlook()) get_mail_address(account = connect_outlook()) get_inbox_name(account = connect_outlook()) get_drafts_name(account = connect_outlook()) get_certe_name(user = Sys.info()["user"], account = connect_outlook()) get_job_title(user = Sys.info()["user"], account = connect_outlook()) get_certe_name_and_job_title( user = Sys.info()["user"], account = connect_outlook() ) get_certe_location(account = connect_outlook()) get_certe_signature(account = connect_outlook(), plain = FALSE)
get_name(account = connect_outlook()) get_department(account = connect_outlook()) get_address(account = connect_outlook()) get_phone_numbers(account = connect_outlook()) get_mail_address(account = connect_outlook()) get_inbox_name(account = connect_outlook()) get_drafts_name(account = connect_outlook()) get_certe_name(user = Sys.info()["user"], account = connect_outlook()) get_job_title(user = Sys.info()["user"], account = connect_outlook()) get_certe_name_and_job_title( user = Sys.info()["user"], account = connect_outlook() ) get_certe_location(account = connect_outlook()) get_certe_signature(account = connect_outlook(), plain = FALSE)
account |
the Microsoft 365 Outlook account object, e.g. as returned by |
user |
Certe user ID, to look up the secret |
plain |
a logical to indicate whether textual formatting should not be applied |
The get_certe_name()
and get_certe_name_and_job_title()
functions first look for the secret user.{user}.fullname
and falls back to get_name()
if it is not available.
After connecting using connect_outlook()
, the get_*()
functions retrieve properties from this connection.
calendar_get_events( start_date = Sys.Date(), end_date = start_date, account = connect_outlook() ) calendar_unavailable_users( start_date = Sys.Date(), end_date = start_date, account = connect_outlook() )
calendar_get_events( start_date = Sys.Date(), end_date = start_date, account = connect_outlook() ) calendar_unavailable_users( start_date = Sys.Date(), end_date = start_date, account = connect_outlook() )
start_date , end_date
|
date range |
account |
the Microsoft 365 Outlook account object, e.g. as returned by |
calendar_get_events()
retrieves a data.frame with all appointments from the shared calendar set in account
.
calendar_unavailable_users()
returns a vector of appointment subjects that are shown as "free" within start_date
and end_date
.
This uses the Microsoft365R
package to download email attachments via Microsoft 365. Connection will be made using connect_outlook()
.
download_mail_attachment( path = getwd(), filename = "mail_{name}_{datetime}", search = "hasattachment:yes", search_subject = NULL, search_from = NULL, search_when = NULL, search_attachment = NULL, folder = get_inbox_name(account = account), n = 5, sort = "received desc", overwrite = TRUE, account = connect_outlook(), interactive_mode = interactive() )
download_mail_attachment( path = getwd(), filename = "mail_{name}_{datetime}", search = "hasattachment:yes", search_subject = NULL, search_from = NULL, search_when = NULL, search_attachment = NULL, folder = get_inbox_name(account = account), n = 5, sort = "received desc", overwrite = TRUE, account = connect_outlook(), interactive_mode = interactive() )
path |
location to save attachment(s) in |
filename |
new filename for the attachments, use
|
search |
an ODATA filter, ignores |
search_subject |
a character, equal to |
search_from |
a character, equal to |
search_when |
a Date vector of size 1 or 2, equal to |
search_attachment |
a character to use a regular expression for attachment file names |
folder |
email folder name to search in, defaults to Inbox of the current user by calling |
n |
maximum number of emails to search |
sort |
initial sorting |
overwrite |
a logical to indicate whether existing local files should be overwritten |
account |
a Microsoft 365 account to use for searching the mails. This has to be an object as returned by |
interactive_mode |
a logical to indicate interactive mode. In non-interactive mode, all attachments within the search criteria will be downloaded. |
search_*
arguments will be matched as 'AND'.
search_from
can contain any sender name or email address. If search_when
has a length over 2, the first and last value will be taken.
Refer to this Microsoft Support page for all filtering options using the search
argument.
## Not run: download_mail_attachment(search_when = "2021-10-28") if (require("certetoolbox")) { download_mail_attachment(search_from = "groningen", search_when = last_week(), filename = "groningen_{date_time}") download_mail_attachment(search_from = "drenthe", search_when = yesterday(), n = 1) } ## End(Not run)
## Not run: download_mail_attachment(search_when = "2021-10-28") if (require("certetoolbox")) { download_mail_attachment(search_from = "groningen", search_when = last_week(), filename = "groningen_{date_time}") download_mail_attachment(search_from = "drenthe", search_when = yesterday(), n = 1) } ## End(Not run)
These functions use the Microsoft365R
R package to send emails via Microsoft 365. They require an Outlook Business account.
mail( body, subject = "", to = NULL, cc = read_secret("mail.auto_cc"), bcc = read_secret("mail.auto_bcc"), reply_to = NULL, attachment = NULL, header = FALSE, footer = FALSE, background = certestyle::colourpicker("certeblauw6"), send = TRUE, markdown = TRUE, signature = get_certe_signature(account = account), automated_notice = !interactive(), save_location = read_secret("mail.export_path"), sent_subfolder = read_secret("mail.sent_subfolder"), expect = NULL, account = connect_outlook(), identifier = NULL, ... ) mail_plain( body, subject = "", to = NULL, cc = read_secret("mail.auto_cc"), bcc = read_secret("mail.auto_bcc"), reply_to = read_secret("mail.auto_reply_to"), attachment = NULL, send = TRUE, ... ) mail_image(image_path, width = NULL, ...) mail_on_error(expr, to = read_secret("mail.error_to"), ...) mail_is_sent(project_number, date = Sys.Date(), account = connect_outlook())
mail( body, subject = "", to = NULL, cc = read_secret("mail.auto_cc"), bcc = read_secret("mail.auto_bcc"), reply_to = NULL, attachment = NULL, header = FALSE, footer = FALSE, background = certestyle::colourpicker("certeblauw6"), send = TRUE, markdown = TRUE, signature = get_certe_signature(account = account), automated_notice = !interactive(), save_location = read_secret("mail.export_path"), sent_subfolder = read_secret("mail.sent_subfolder"), expect = NULL, account = connect_outlook(), identifier = NULL, ... ) mail_plain( body, subject = "", to = NULL, cc = read_secret("mail.auto_cc"), bcc = read_secret("mail.auto_bcc"), reply_to = read_secret("mail.auto_reply_to"), attachment = NULL, send = TRUE, ... ) mail_image(image_path, width = NULL, ...) mail_on_error(expr, to = read_secret("mail.error_to"), ...) mail_is_sent(project_number, date = Sys.Date(), account = connect_outlook())
body |
body of email, allows markdown if |
subject |
subject of email |
to |
field 'to', can be character vector |
cc |
field 'CC', can be character vector |
bcc |
field 'BCC', can be character vector |
reply_to |
field 'reply-to' |
attachment |
character (vector) of file location(s), or (a list of) data.frames |
header , footer
|
extra text for header or footer, allows markdown if |
background |
background of the surrounding area in the email. Use |
send |
directly send email, |
markdown |
treat body, header and footer as markdown |
signature |
text to print as email signature, or |
automated_notice |
a logical to print a notice that the mail was sent automatically (default is |
save_location |
location to save email object to, which consists of all email details and can be printed in the R console |
sent_subfolder |
mail folder within Sent Items in the Microsoft 365 account, to store the mail if |
expect |
expression which should return |
account |
a Microsoft 365 account to use for sending the mail. This has to be an object as returned by |
identifier |
a mail identifier to be printed at the bottom of the email. Defaults to |
... |
arguments for |
image_path |
path of image |
width |
required width of image, must be in CSS style such as "200px" or "100%" |
expr |
expression to test, an email will be sent if this expression returns an error |
project_number |
Number of a project. Will be used to check the grey identifier in the email. |
date |
A date, defaults to today. Will be evaluated in |
mail_on_error()
can be used for automated scripts.
mail_plain()
sends a plain email, without markdown support and with no signature.
Use mail_is_sent()
to check whether a project email was sent on a certain date from any Sent Items (sub)folder. The function will search for the grey identifier in the email body, which is formatted as [-yymmdd][0-9]+[-project_number][^0-9a-z]
. It returns TRUE
if any email was found, and FALSE
otherwise. If TRUE
, the name will contain the date(s) and time(s) of the sent email.
mail("test123", "test456", to = "[email protected]", account = NULL) mail_plain("test123", "test456", to = "[email protected]", account = NULL) mail(mail_image(image_path = system.file("test.jpg", package = "certemail")), "test456", to = "[email protected]", account = NULL) # data.frames will be transformed with certestyle::plain_html_table() mail(body = mtcars[1:5, ], subject = "Check these cars!", to = "[email protected]", account = FALSE) # but better is to add as an attachment - they will become Excel files mail(body = "Hello there", subject = "Check these cars!", to = "[email protected]", attachment = mtcars[1:5, ], account = FALSE) # use list() to add multiple data sets mail(body = "Hello there", subject = "Check these cars and flowers!", to = "[email protected]", attachment = list(mtcars[1:5, ], iris), account = FALSE)
mail("test123", "test456", to = "[email protected]", account = NULL) mail_plain("test123", "test456", to = "[email protected]", account = NULL) mail(mail_image(image_path = system.file("test.jpg", package = "certemail")), "test456", to = "[email protected]", account = NULL) # data.frames will be transformed with certestyle::plain_html_table() mail(body = mtcars[1:5, ], subject = "Check these cars!", to = "[email protected]", account = FALSE) # but better is to add as an attachment - they will become Excel files mail(body = "Hello there", subject = "Check these cars!", to = "[email protected]", attachment = mtcars[1:5, ], account = FALSE) # use list() to add multiple data sets mail(body = "Hello there", subject = "Check these cars and flowers!", to = "[email protected]", attachment = list(mtcars[1:5, ], iris), account = FALSE)