1

I'd like to reply all to an email in Outlook (say, the first object in emails below), but can't reconcile how to create a new mail object and reply all to that first object in emails.

require(RDCOMClient)
require(tidyverse)
OutApp <- COMCreate("Outlook.Application")
search <- OutApp$AdvancedSearch("Inbox", "urn:schemas:mailheader:date > '2020-12-7 00:12:30'") # searches emails sent in the last few hours
results <- search$results()
emails <- purrr::map(seq(results$Count()), function(x) results$Item(x))

These emails will come with specific properties like unique Outlook ID's, etc., but I'm not quite sure where to go from there.

Below, we can create an Outlook item, but how do we edit that email and route is as the ReplyAll() to the specific email we've flagged?

outMail = OutApp$CreateItem(0) # Object type 0 = mail item
outMail[["HTMLbody"]] = "Hi everyone in this email chain. I sent this with R. Crazy!"
*outMail$ReplyAll(???)* # What here? Eternal mystery

Another potential option I've had some luck with is the mailR package, but don't know how to reply to a specific email.

require(mailR)

send.mail(from = "myemail@acct.com", to = "listofrecpts@acct.com",
          subject = "Subject",
          body = "This is supposed to be a reply all...",
          html = TRUE, inline = TRUE,
          smtp = list(host.name = "10.24.3.5", port = 25),
           authenticate = FALSE, send = TRUE)

Alas, I have no idea how to point it towards another email object in Outlook, even if I have a specific pointer/email ID.

Any advice?

1 Answers1

0

You would need to retrieve a particular item from the Results collection and call MailItem.Reply or MailItem.ReplyAll instead of Application.CreateItem.

Dmitry Streblechenko
  • 56,873
  • 3
  • 44
  • 75
  • Thanks, Dmitry. How do I pass along arguments (i.e. body & attachment) to the email[[1]]$ReplyAll() item? If I amend email[[1]]["Body"], for example, won't I be altering the original message? – BSHuniversity Dec 07 '20 at 22:02
  • 1
    `ReplyAll` returns a new `MailItem` object with the body, subject, recipients, etc. prepopulated. You would need to merge your data with whatever Outlook set. – Dmitry Streblechenko Dec 08 '20 at 02:22