2017-08-27 205 views
0

我試圖通過R代碼從我的Outlook發送電子郵件。它在大多數情況下運作良好。我正在使用RDCOMClient來完成我所需要的工作。RDCOMClient + Outlook電子郵件

唯一的問題是簽名;我想在這個環節上作出批示:

How to add my Outlook email signature to the COM object using RDCOMClient

然而,我的簽名獲取與該行的電子郵件的正文覆蓋:

outMail[["HTMLBody"]] = paste0('<p>some body', signature, '</p>') 

回答

1

讓我知道如果這個代碼可以解決你是什麼尋找。您需要使用paste命令將身體粘貼到簽名中。見下文。

library(RDCOMClient) 

# This is the original body you have created 
original_body <- "This body has been created to just for visualization" 
# Adding signature which can be modified as required 
# The <br> is html tag for line break. Anything typed after this will move to next line 
Your_Signature <- paste0("Thanks & Regards,<br>", "YourName") 
# Creating new body which will be used in email 
new_body <- paste("<p>",original_body, "</p>", Your_Signature) 

# init com api 
OutApp <- COMCreate("Outlook.Application") 
# create an email 
outMail = OutApp$CreateItem(0) 
# configure email parameter 
outMail[["To"]] = "[email protected]" 
outMail[["subject"]] = "TEST" 
outMail[["HTMLbody"]] = new_body 
# send it      
outMail$Send() 

您將收到一封電子郵件,其輸出如下所示。

Email Output

解決方案2: 既然你沒有提供已使用的代碼,我用我自己的代碼和固定使用GetInspector時arised簽名問題。讓我知道這是否有幫助。

library(RDCOMClient) 

OutApp <- COMCreate("Outlook.Application") 
outMail = OutApp$CreateItem(0) 

# Get signature from outlook 
# GetInspector renders the message in html format. 
# Note that if you have not created any signatures, this will return blank 
outMail$GetInspector() 
Signature <- outMail[["HTMLbody"]] 

# Define the body of you email separately 
body <- "Define your body here." 

outMail[["To"]] = "[email protected]" 
outMail[["subject"]] = "TEST EMAIL" 

# Paste the body and signatures into the email body 
outMail[["HTMLbody"]] = paste0("<p>", body, "</p>", Signature) 
outMail$Send()