Reputation: 91
I have text data that I read from a file; I need to place it in the body of an email message. There are about 50 such data items to be placed into existing text.
It seems I should be able to put a marker (dataItem1, dataItem2, etc.) and replace that with the matching text data from the file.
Searches only turn up replacing field data such as Recipient, Subject, etc., or replacing the entire body. Would I have to generate the entire body in the code? Seems like I should be able to "insert" a data item into existing body text.
Any suggestions will be much appreciated.
Upvotes: 1
Views: 28332
Reputation: 827
Just in case your email is formatted as HTML, and you don't want to lose the formatting, here's what you want to do.
myMessage.HTMLBody = Replace(myMessage.HTMLBody, "dataItem1", "replacement item")
Upvotes: 4
Reputation: 620
Use the Body
property of the MailItem
you're working with. Assign it to a variable and you can edit it:
Dim body As String
body = myMessage.Body
body = Replace(body,"dataItem1","your replacement here")
Then assign the variable to the Body
:
myMessage.Body = body
Upvotes: 0