R/download_mail_attachment.R
download_mail_attachment.Rd
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,
skip_inline = TRUE,
account = connect_outlook(),
interactive_mode = interactive()
)
location to save attachment(s) to
new filename for the attachments, use NULL
to not alter the filename. For multiple files, the files will be appended with a number. The following texts can be used for replacement (invalid filename characters will be replaced with an underscore):
"{date}"
, the received date of the email in format "yyyymmdd"
"{time}"
, the received time of the email in format "HHMMSS"
"{datetime}"
and "{date_time}"
, the received date and time of the email in format "yyyymmdd_HHMMSS"
"{name}"
, the name of the sender of the email
"{address}"
, the email address of the sender of the email
"{original}"
, the original filename of the attachment
an ODATA filter, ignores sort
and defaults to search only mails with attachments
a character, equal to search = "subject:(search_subject)"
, case-insensitive
a character, equal to search = "from:(search_from)"
, case-insensitive
a Date vector of size 1 or 2, equal to search = "received:date1..date2"
, see Examples
a character to use a regular expression for attachment file names
email folder name to search in, defaults to Inbox of the current user by calling get_inbox_name()
maximum number of emails to search
initial sorting
a logical to indicate whether existing local files should be overwritten
a logical to indicate whether inline attachments such as meta images must be skipped
a Microsoft 365 account to use for searching the mails. This has to be an object as returned by connect_outlook()
or Microsoft365R::get_business_outlook()
.
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.
if (FALSE) { # \dontrun{
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)
}
} # }