• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

How can I copy the RTF-Body + Attachments and Insert them in an other E-Mail with vbscript

Hello,

I hope anybody can help me.
I have written an Outlook Script that opens an Item, using MAPI and Inserts the fields in an other Item.
Everything works fine, I can copy the subject with
Item.Subject = OldItem.Subject

Except of the body. It is in RTF Format and has embedded Items, for example jpg´s or bmp´s.
If I say
Item.Body = OldItem.Body I only get the Text but not the Attachements.

Has anybody an Idea how to manage it?

mfg

Jürgen St. from Germany
0
kks81
Asked:
kks81
  • 3
  • 3
1 Solution
 
stefriCommented:
Attachements do not belong to message body but to OldItem.attachments collection

0
 
kks81Author Commented:
For sure, but I thought there might be an object to add both in one like
"Item.Body&Attachments = OldItem.Body&Attachments"

But I haven´t found anything. My Code looks like this, but is very slow on old 100MHz PCs and has an other disadvantage; If you insert a picture not as file but as object (Menu->Insert->object->from file), it is not in the attachment.

               '#########################
               'Anlagen einfügen
               Set fso = CreateObject("Scripting.FileSystemObject")
               Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
               strPath = fldTemp.Path & "\"
               For i = 1 to MyPH.Attachments.count
                    strFile = strPath & MyPH.Attachments(i).FileName
                    MyPH.Attachments(i).SaveAsFile strFile
                    Item.Attachments.Add strFile               ', , , objAtt.DisplayName
                    Item.Attachments(i).Position = MyPH.Attachments(i).Position
                    Item.Attachments(i).DisplayName = MyPH.Attachments(i).DisplayName
                    Item.Attachments(i).FileName = MyPH.Attachments(i).FileName
                    DoEvents     'Notwendig, damit die Dateien erst nachdem Sie eingefügt wurden gelöscht werden.
                    'fso.DeleteFile strFile
               Next
               Set fldTemp = Nothing
               Set fso = Nothing
               '#########################
0
 
stefriCommented:
This is exactly the code I was thinking about. But what is the purpose of Doevents?


Apparently you want to copy myPH to a new mail, why not using myPh.copy and maybe later modify the messagebody?

Stefri
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
kks81Author Commented:
The purpose of the DoEvents was that I got an error as the
fso.DeleteFile strFile
wasn´t quoted.
Now I have changed the script a little (Read the filenames in an arrey and delete the files at the end of the script), so that the DoEvents is not longer needed.

I can´t use the .copy method, because I call the script from a customized form, with a button "New Version", then comes an inputbox "Please insert the number of the old Form" and I use the find-Method to open the old form and take over several filds.

I never thought of opening a new form from the old, but that could be the better way, less code and no trouble with attachments. I´ll try that.
Do you know an easy way to find and open the new created form?
0
 
kks81Author Commented:
Ok, fine!

This code works:
     set MyNameSpace = Application.GetNameSpace("MAPI")
     Set Folder0 = MyNameSpace.Folders("Postfach - Me")
     Set Folder1 = Folder0.Folders("Postausgang")
     Set objTemp = Item.copy
     Call objTemp.Move(Folder1)
     objTemp.Display

Thanks a lot for the idea, much easier, if I had thought about that, I could have saved lot of work.
0
 
stefriCommented:
You are welcome
Sharing problems allows new ideas to emerge.

Stefri
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now