我通过描述文件使用 RDCOMClient 获得了 R 包:
建议:RDCOMClient
以及以下(完美运行)代码:
GetNewWrd <- function() {
stopifnot(require(RDCOMClient))
# Starts the Word application with wrd as handle
wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
newdoc <- wrd[["Documents"]]$Add("",FALSE, 0)
wrd[["Visible"]] <- TRUE
invisible(wrd)
}
Run Code Online (Sandbox Code Playgroud)
如今,这似乎被认为是不好的做法,“编写 R 扩展,1.1.3.1 建议的包”告诉我们要制定:
if (requireNamespace("rgl", quietly = TRUE)) {
rgl::plot3d(...)
} else {
## do something else not involving rgl.
}
Run Code Online (Sandbox Code Playgroud)
或者: ..如果想要在建议的包不可用时给出错误,只需使用例如 rgl::plot3d。
重新编码(根据我的理解)意味着,只需删除要求语句:
GetNewWrd <- function() {
# Starts the Word application with wrd as handle
wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
newdoc <- …Run Code Online (Sandbox Code Playgroud) 我正在研究RDCOMClient到我的一些工作流程并感谢agstudy的答案在这里我能够发送电子邮件,但我无法弄清楚如何添加我的Outlook电子邮件签名.我是COM对象的新手,但已经做了相当多的搜索并且没有找到任何东西.因为我的声誉尚未达到50,我无法评论那里的初始线索.有人可以告诉我如何添加我的Outlook电子邮件签名吗?
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "dest@dest.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
## I want to add my outlook signature here.
outMail$Send()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用htmlTable包将数据帧转换为 html 表,然后RDCOMClient通过附加 html 表作为电子邮件正文,使用 Microsoft Outlook 作为使用包的电子邮件客户端发送电子邮件。我是 HTML 编码的新手,所以我不太熟悉如何使用 HTML 标签格式化表格。下面是我正在尝试做的一个例子。
# Library to send email from Microsoft Outlook
library(RDCOMClient)
# Library to create HTML table
library(htmlTable)
# Reading data from inbuilt 'mtcars' dataset
x <- head(mtcars)
# Create HTML table
y <- htmlTable(x,
rnames = FALSE,
caption="This is from htmlTable package",
align = paste(rep("c", ncol(x)), collapse = "|"),
align.header = paste(rep("c", ncol(x)), collapse = "|"))
# add the table as body of the email …Run Code Online (Sandbox Code Playgroud) 我在R中运行一项日常任务,该任务从Outlook中检索电子邮件(附加了csv文件),对csv文件进行一些分析,并将结果数据帧写入公司的本地驱动器。某些早晨,我发现文件尚未交付,并且根据日志,原因是以下错误:
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Execution halted
Run Code Online (Sandbox Code Playgroud)
我找不到发生这种情况的日子的任何模式。一旦我手动触发任务,它通常运行良好。
我已经在其他问题中看到了此错误,但是这些问题与通过Outlook发送附件有关,而我没有这样做。以下是我访问Outlook和检索数据的代码:
library(RDCOMClient)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:subject = 'My_Subject'"
)
Sys.sleep(5)
results <- search$Results()
for (i in 1:results$Count()) {
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime())
== as.Date(strptime(Sys.time(),format = "%Y-%m-%d"))) {
email <- results$Item(i)
}
}
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file,sep=",",fileEncoding="UCS-2LE")
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 从辅助电子邮件地址发送电子邮件RDCOMClient。我听取了如何使用 R RDCOMClient 检索 Outlook 收件箱电子邮件?并尝试用 VBA 编写并翻译,但无法获得正确的命令。
注意:我无法使用,SentOnBehalfOfName因为我没有必要的权限。
以下 VBA 和 Python 代码均成功从辅助收件箱发送电子邮件。
编程语言
Sub SendUsingAccount()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
Set oAccount = Application.Session.Accounts.Item(2) 'Index of Mailbox
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using MAPI Account"
oMail.Recipients.Add "email@email.com"
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End Sub
Run Code Online (Sandbox Code Playgroud)
Python
import win32com.client
o = win32com.client.Dispatch("Outlook.Application")
oacctouse = None
for oacc in o.Session.Accounts:
if oacc.SmtpAddress == "myemail@email.com":
oacctouse = oacc
break
#print …Run Code Online (Sandbox Code Playgroud) 我一直在使用 RDCOMClient 包,如此处所述通过 Outlook 在 R 中发送电子邮件。Outlook 2010 和 Windows 7 一切正常。脚本不起作用,因为我已将系统更改为带有 Outlook 2016 的 Windows 10。
这是脚本:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "test"
outMail[["body"]] = "Test."
outMail$Send()
Run Code Online (Sandbox Code Playgroud)
它在最后一行失败,错误如下:
80004004 不支持 InterfaceSupportsErrorInfo checkErrorInfo -2147467260 错误:操作中止
建议的解决方法是打开消息框并模拟按 Ctrl+Enter:
library(KeyboardSimulator)
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "test"
outMail[["body"]] = "Test."
outMail$Display()
Sys.sleep(3)
keybd.press('Ctrl+Enter')
Run Code Online (Sandbox Code Playgroud)
但是这种方法并不是100%可靠的。
你知道如何让 outMail$Send() 再次工作吗?
谢谢!
我正在使用的 Outlook 帐户设置了多个邮箱,尽管以下答案似乎显示了如何使用该功能,但我无法使其正常工作,因为我有多个带有“收件箱”文件夹的邮箱。 使用 R 从 Outlook 电子邮件下载附件
要正常访问相关文件夹,我将使用以下代码:
OutApp = COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder = outlookNameSpace$Folders(14)$Folders("Inbox")
Run Code Online (Sandbox Code Playgroud)
在调用下面的收件箱之前,我似乎需要另一行左右:
search = OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject = 'test subject'")
Run Code Online (Sandbox Code Playgroud) library("tm")
library("NLP")
library("dplyr")
library("readtext")
library("readxl")
library("foreach")
library("devtools")
library("RDCOMClient")
library("rlist")
WDF = vector()
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folderName = "Folder Name"
fld <- outlookNameSpace$GetDefaultFolder(6)
fld = fld$folders(folderName)
Cnt = fld$Items()$Count()
emails <- fld$items
df = data.frame(sno = 1:Cnt,Text = "",stringsAsFactors=FALSE)
for(i in 1:10){
d = as.data.frame(emails(i)$Body(), stringsAsFactors=FALSE)
df$Text[i] = d[1]
df$Sender[i] = emails(i)[['SenderName']]
df$To[i] = emails(i)[['To']]
df$sub[i] = emails(i)[['subject']]
}
emails(2)[['SenderName']]
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码获取发件人电子邮件地址:
emails(2)[['SenderEmailAddress']]
Run Code Online (Sandbox Code Playgroud)
但它最终给出了这样的:
[1] "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=E4CD239AB9F44AC4AC0A4015B6F4805A-RATINGSDIRE"
Run Code Online (Sandbox Code Playgroud) 目前我正在为客户准备 R 课。我们想从受密码保护的 xlsx 文件中读取数据。因此,我试图将这个受密码保护的 xlsx 文件读入 R(取消保护文件本身不是解决方案)。不幸的是,我无法使用包括安装其他软件(例如 Java)的方法。
无论openxlsx,readr也不readxl似乎使用密码Excel文件中读取时支持。
有两个包似乎支持这个:xlsx和excel.link 我试过xlsx包,但它需要 Java。XLConnect也是如此
我已经尝试过excel.link包,但每次我尝试打开文件时它都会崩溃(“R 会话中止”)。RDCOMClient也是如此。
不幸的是,Stackoverflow 帖子不适合我的问题:
遇到这些问题后,我只是更新了我的所有软件包。这是有关我的 R 版本的信息。
version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 4
minor 0.3
year 2020
month 10 …Run Code Online (Sandbox Code Playgroud) 我可以通过 RDCOMClinet 包将 Excel 文件附加到 Outlook 中。但是如何通过R在邮件正文中显示excel工作表内容?假设工作表中包含一个表格和一个图形。
library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email
outMail = OutApp$CreateItem(0)
## configure email parameter
outMail[["To"]] = "name@email.com"
outMail[["subject"]] = paste0("Report ", Sys.Date() - 1)
# attach a file via its directory
dirs <- dir(getwd(), full.names = TRUE)
outMail[["Attachments"]]$Add(dirs)
# insert an excel worksheet from attachment or local drive
outMail[["HTMLBody"]] = ?
Run Code Online (Sandbox Code Playgroud) 我无法使用 R-3.6 安装 RDCOMClient
一些背景:RDCOMClient 在我的 R-3.51 实例中工作,我需要使用 3.6,我需要使用 RDCOMClient 与我桌面的 Outlook 交互。mailR 和 sendmailR 目前不是一个选项。
我试过的事情:
>install.packages("RDCOMClient")
Installing package into ‘C:/Users/<user>/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘RDCOMClient’ is not available (for R version 3.6.0)
Run Code Online (Sandbox Code Playgroud)
> library("devtools")
> install_github('omegahat/RDCOMClient')
Error: Failed to install 'unknown package' from GitHub:
Timeout was reached: Connection timed out after 10000 milliseconds
Run Code Online (Sandbox Code Playgroud)
> install.packages("RDCOMClient", repos = "http://www.omegahat.org/R")
Installing package into ‘C:/Users/<users>/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,如下所示。然后我将数据框转换为 html 表。
# Use RDCOMClient to send email from outlook
library(RDCOMClient)
# Use xtable to convert dataframe into html table
library(xtable)
# Create dataframe
df <- as.data.frame(mtcars[1:3,1:3])
# Create HTML object
df_html <- xtable(df)
Run Code Online (Sandbox Code Playgroud)
现在,我正在使用电子邮件线程通过 Outlook 在 R 中发送电子邮件中给出的绝妙解决方案从 Outlook发送电子邮件
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email
outMail = OutApp$CreateItem(0)
## configure email parameter
outMail[["To"]] = "dest@dest.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = df_html
## send it
outMail$Send()
Run Code Online (Sandbox Code Playgroud)
对于我的电子邮件正文,我想要我想作为 html 表附加的数据框 df。当我执行上述代码时,我收到以下错误消息。 …
我有一个R脚本,我希望在完成后使用Microsoft Outlook自动发送电子邮件.我正在使用"RDCOMClient"软件包,我想在电子邮件中添加多个附件.
这是我正在尝试使用的代码:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = paste("recipient@account.com","another@gmail.com", sep=";", collapse=NULL)
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
outMail[["attachments"]]$Add("C:/Path/To/The/Attachment/File.ext")
outMail$Send()
Run Code Online (Sandbox Code Playgroud)
我尝试使用粘贴作为附件,如"收件人"选项,但我99%肯定这是打破附件的原因,因为它只适用于一个.它非常适合添加多个收件人.有谁知道如何使用此包添加多个附件?
r ×13
rdcomclient ×13
outlook ×9
email ×4
html-email ×2
com ×1
cran ×1
css ×1
excel ×1
openxlsx ×1
outlook-2016 ×1
package ×1
readxl ×1
sender ×1
windows-10 ×1
xtable ×1