|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Send an email with attachment through default email clientpop 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("%TEMP%"), _ "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).Items().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 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. Show quoteHide quote On Apr 13, 9:46 am, "Ben K" <benk***@hotmail.com> wrote: > 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("%TEMP%"), _ > "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).Items().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 On 13 Apr 2007 00:46:47 -0700, Ben K wrote:
Show quoteHide quote > I saw some posting some time ago regarding a "trick" to automatically You can use Process.Start with the mailto: keyword. It also supports> 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("%TEMP%"), _ > "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).Items().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 attachments http://thinkersroom.com/bytes/2007/02/20/neat-enail-trick/ Rad,
Thanks for replying. However, I found another link (http:// www.thescripts.com/forum/thread351279.html) saying that "mailto:" does not support attachment. Is it a new interface that I can use to add attachment? Best regards, Ben Show quoteHide quote On Apr 14, 12:15 am, "Rad [Visual C# MVP]" <nos...@nospam.com> wrote: > On 13 Apr 2007 00:46:47 -0700, Ben K wrote: > > > > > 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("%TEMP%"), _ > > "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).Items().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 > > You can use Process.Start with the mailto: keyword. It also supports > attachments > > http://thinkersroom.com/bytes/2007/02/20/neat-enail-trick/ > -- > Bits.Byteshttp://bytes.thinkersroom.com On 16 Apr 2007 01:07:54 -0700, Ben K wrote:
> Rad, Yes, you're right. Mailto does not support attachments. I could have sworn> > Thanks for replying. However, I found another link (http:// > www.thescripts.com/forum/thread351279.html) saying that "mailto:" does > not support attachment. Is it a new interface that I can use to add > attachment? > > Best regards, > that it did but digging around has convinced me otherwise. Rad,
So, is there anyway I can simulate the 3 steps in my original posting using C# automation? 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. Ben Show quoteHide quote On Apr 16, 11:54 am, "Rad [Visual C# MVP]" <nos...@nospam.com> wrote: > On 16 Apr 2007 01:07:54 -0700, Ben K wrote: > > > Rad, > > > Thanks for replying. However, I found another link (http:// > >www.thescripts.com/forum/thread351279.html) saying that "mailto:" does > > not support attachment. Is it a new interface that I can use to add > > attachment? > > > Best regards, > > Yes, you're right. Mailto does not support attachments. I could have sworn > that it did but digging around has convinced me otherwise. > -- > Bits.Byteshttp://bytes.thinkersroom.com
Other interesting topics
Static vs Non-static
ObjectDataSource not refreshing correctly from a business Object Refactoring class location closing excel from c# Passing an arraylist which contains a struct which contains an arraylist Screen Scraping a Password Protected Site Simple animation and stuff... Screen resolution & color depth for website Exception when accessing backgroundWorker.CancellationPending Need Help: Common IsolatedStorage per user regardless of application |
|||||||||||||||||||||||