Hmm this code looks quite scary...
You seem to be looking for "System.diagnostics.runas", IE from a COM
reference and "System.Environment" - and then some Specialfolder...
Perhaps System.io.Path / File for temporary files... so on
But perhaps it is also an idea to just use the Outlook API (reference
the outlook com component) to create a mail with an attachment...
Cheers,
Stefan.
On Apr 13, 9:46 am, "Ben K" <benk...@hotmail.comwrote:
Quote:
I saw some posting some time ago regarding a "trick" to automatically
pop up an email editor with attachment using the default mail client.
It is
basically using automation to do the following steps
>
1. Using Explorer and copy a file, "C:\temp\attachment.txt"
2. Locate the item of type "MAPIMAIL File" in "SendTo" in Explorer
(i.e. the default mail client program)
3. Paste the file to the "MAPIMAIL File" item in "SendTo". This will
cause a mail editor pops up with with the file copied in Step 1
as its attachment.
>
How do I create C# automation that emulates the manual steps above?
Below is the code in VB Script I got that does that.
================================================== =
Option Explicit
Dim fso, oWShell, ie, oMapiMailItems, item
Dim strGuid, archive, cmdline
Set fso = CreateObject( "Scripting.FileSystemObject" )
>
' seems a bug in the Guid method requires us to clip the returned
string
strGuid = Left(CreateObject("Scriptlet.TypeLib").Guid, 38)
>
Set oWShell = CreateObject("WScript.Shell")
archive = fso.BuildPath(oWShell.ExpandEnvironmentStrings("%T EMP%"), _
"MyEncryptor_" & strGuid & ".fta" )
>
cmdline = "MyEncryptor.exe -r -f " & archive & " -o " & """" &
WScript.Arguments(0) & """"
>
oWShell.Run cmdline,,True
>
Set ie=CreateObject("InternetExplorer.Application")
>
ie.Navigate "c:\"
Do While ie.Busy Or ie.ReadyState<>4
WScript.Sleep 100
Loop
>
Const ssfSENDTO=9 'ShellSpecialFolderConstants.ssfSENDTO
Const ssfDESKTOP=0 ' ShellSpecialFolderConstants.ssfDESKTOP
ie.Document.Application.NameSpace(ssfDESKTOP).Item s().Item(archive).InvokeVerb
"copy"
>
Set oMapiMailItems =
ie.Document.Application.NameSpace(ssfSENDTO).Items
For Each item in oMapiMailItems
If item.Type = "MAPIMAIL File" Then
item.InvokeVerb "paste"
Exit For
End If
Set item = Nothing
Next
>
Set oMapiMailItems = Nothing
ie.Quit
Set ie = Nothing
WScript.Quit
Set WScript = Nothing
Set oWShell = Nothing
Set fso = Nothing