7

I am working RDCOMClient into some of my work flow and thanks to agstudy's answer Here I am able to send emails throuhg r, but I can't figure out how to add my Outlook email signature. I'm new to COM objects, but have done a fair share of searching and haven't found anything. Because my reputation hasn't hit 50 yet, I wasn't able to comment on the inital thread to ask there. Can someone show me how I can add my Outlook email signature?

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()
Parfait
  • 104,375
  • 17
  • 94
  • 125
Ben
  • 175
  • 1
  • 3
  • 10
  • For your solution, you use an auto-signature. Do you know how to use a not auto-signature (in fect, I have 2 signatures and I want to use – Guillaume Jan 20 '19 at 16:16

1 Answers1

10

Consider using Outlook's GetInspector() property. Assuming you have an auto-signature, assign a variable to capture the default body and then concatenate to your latter message:

library(RDCOMClient)

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

outMail$GetInspector()
signature = outMail[["HTMLBody"]]

outMail[["Recipients"]]$Add("dest@dest.com")
outMail[["Subject"]] = "some subject"
outMail[["HTMLBody"]] = paste0('<p>some body', signature, '</p>')

outMail$Display()
outMail <- NULL
OutApp <- NULL
Parfait
  • 104,375
  • 17
  • 94
  • 125
  • 1
    Thanks Parfait. This works for adding the information, do you know how to keep the formatting of the text and any images that are included in the signature? Right now it just has a link to the image: cid:image001.jpg@01D0251C.073EC2D0 – Ben Jun 17 '16 at 14:37
  • 1
    Yes, GetInspector renders the message in html format. Try using *HTMLBody* over *Body*. See edit with `outMail[['HTMLBody']]` in both the signature and message calls. You can adjust fonts/sizes/colors with inline html markup (no css). See how message is wrapped in `

    ` tags.

    – Parfait Jun 17 '16 at 14:57