I have a shared email account for my group at work. I've used StackOverflow to very helpfully automate the process of sending an email with multiple attachments from my personal email but I'd like to change the address to be from the shared email address. I notice that in outMail we have "To" "subject" "cc" body" etc. but there is no way to change "FROM." i.e. outMail[["From"]] Does anyone have any ideas?
Asked
Active
Viewed 276 times
2
-
Can you please share your code example? – sm925 Feb 13 '18 at 16:36
-
##Send Ooutlook Email OutApp <- COMCreate("Outlook.Application") outMail = OutApp$CreateItem(0) outMail[["To"]] = "me@gmail.com" outMail[["subject"]] = "Test" outMail[["body"]] = "Hello" path = paste0(out_dir,Sys.Date()) setwd(paste0(path)) for(j in 1:length(dir())){ outMail[["attachments"]]$Add((paste(path,dir()[j],sep="/"))) } outMail$Send() – Jay Feb 13 '18 at 16:54
-
Why don't you try `sendmailR` or `mailR`? – sm925 Feb 13 '18 at 16:58
-
Thanks! I didn't know those existed. Yes, this looks like one of these is a better option for me as I think in order to use the COMCreate() function I'll need to change Outlook...something I do not want to do. – Jay Feb 13 '18 at 17:14
1 Answers
0
Here is an approach that can be considered :
library(RDCOMClient)
vec_to <- c("email1@hotmail.com", "email2@hotmail.com")
vec_cc <- ""
vec_bcc <- ""
char_subject <- "Hi"
char_body <- "Hi"
char_htmlbody <- ""
vec_attachments <- ""
Outlook <- RDCOMClient::COMCreate("Outlook.Application")
Email <- Outlook$CreateItem(0)
Email[["to"]] <- vec_to
Email[["cc"]] <- vec_cc
Email[["bcc"]] <- vec_bcc
Email[["subject"]] <- char_subject
Email[["SentOnBehalfOfName"]] <- "sharedEmail@hotmail.com"
if(char_body != "" && char_htmlbody != "")
{
stop("Error")
}
if(char_htmlbody == "")
{
Email[["body"]] <- char_body
}else
{
Email[["htmlbody"]] <- char_htmlbody
}
if(vec_attachments[1] != "")
{
for(i in seq_along(vec_attachments))
{
Email[["attachments"]]$Add(vec_attachments[i])
}
}
Email$Send()

Emmanuel Hamel
- 1,769
- 7
- 19