2

I am trying to send emails from my outlook via an R-Code. It is working well for most part. I am using the RDCOMClient to do what I need.

The only issue is the Signature; I tried instructions given in this link:

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

However, my signature gets overwritten with the body of the email in this line:

outMail[["HTMLBody"]] = paste0('<p>some body', signature, '</p>')
James Z
  • 11,838
  • 10
  • 25
  • 41

1 Answers1

2

Let me know if this code solves what you are looking for. You need to paste the body with signature using the paste command. See below.

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"]] = "test@test.com"
outMail[["subject"]] = "TEST"
outMail[["HTMLbody"]] = new_body
# send it                     
outMail$Send()

You will get an email with output as shown below.

Email Output

SOLUTION 2: Since you have not provided the code that was used, I have used my own code and fixed the signature issue that arised when using GetInspector. Let me know if this helps.

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"]] = "test@test.com"
outMail[["subject"]] = "TEST EMAIL"

# Paste the body and signatures into the email body
outMail[["HTMLbody"]] = paste0("<p>", body, "</p>", Signature)
outMail$Send()
Code_Sipra
  • 1,211
  • 3
  • 13
  • 32