I need to automate the generation of an email from an intranet web page. This email needs to be created cient side, as the senders will need to be able to review the mail and attachments before it is sent, and it needs to go from their own account and be filed in their sent items etc. I am working with office 2007, but my users are on a mixture of office 2003 and 2007.
I have found that I am not able to automate outlook from IE using VBScript. When I try to create an instance of an outlook application, I get an error that the activeX object cannot be created . I assume this must be a security feature as I can automate outlook from Excel and Access. I don't know if there is a way around this, but I have failed to find one so far.
I am able to automate word from IE, so I thought as a workaround i may be able to create the email in Word. This script works fine and creates and the email using word when outlook is closed, but when outlook is open it fails when I try to display the envelope information. When this happens, if I go into the word app that is created and try to manually set the envelopevisible property to true, I get an error -2147467259 (80004005).
I'm getting a bit stumped now and would be grateful for any ideas?
dim app, doc
set app = createobject("Word.Application")
app.Visible = true
doc = app.Documents.Add
'Set body text
app.ActiveDocument.Range.Text = "Text Area"
'Set mail details
app.ActiveWindow.EnvelopeVisible = True
app.ActiveDocument.MailEnvelope.Item.Subject = document.getElementById("<%=MailSubject.ClientID%>").Value