473,774 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send an email with attachment through default email client

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\attach ment.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.File SystemObject" )

' seems a bug in the Guid method requires us to clip the returned
string
strGuid = Left(CreateObje ct("Scriptlet.T ypeLib").Guid, 38)

Set oWShell = CreateObject("W Script.Shell")
archive = fso.BuildPath(o WShell.ExpandEn vironmentString s("%TEMP%"), _
"MyEncrypto r_" & strGuid & ".fta" )

cmdline = "MyEncryptor.ex e -r -f " & archive & " -o " & """" &
WScript.Argumen ts(0) & """"

oWShell.Run cmdline,,True

Set ie=CreateObject ("InternetExplo rer.Application ")

ie.Navigate "c:\"
Do While ie.Busy Or ie.ReadyState<> 4
WScript.Sleep 100
Loop

Const ssfSENDTO=9 'ShellSpecialFo lderConstants.s sfSENDTO
Const ssfDESKTOP=0 ' ShellSpecialFol derConstants.ss fDESKTOP
ie.Document.App lication.NameSp ace(ssfDESKTOP) .Items().Item(a rchive).InvokeV erb
"copy"

Set oMapiMailItems =
ie.Document.App lication.NameSp ace(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

Apr 13 '07 #1
5 13313
Hmm this code looks quite scary...

You seem to be looking for "System.diagnos tics.runas", IE from a COM
reference and "System.Environ ment" - 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...@hotmai l.comwrote:
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\attach ment.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.File SystemObject" )

' seems a bug in the Guid method requires us to clip the returned
string
strGuid = Left(CreateObje ct("Scriptlet.T ypeLib").Guid, 38)

Set oWShell = CreateObject("W Script.Shell")
archive = fso.BuildPath(o WShell.ExpandEn vironmentString s("%TEMP%"), _
"MyEncrypto r_" & strGuid & ".fta" )

cmdline = "MyEncryptor.ex e -r -f " & archive & " -o " & """" &
WScript.Argumen ts(0) & """"

oWShell.Run cmdline,,True

Set ie=CreateObject ("InternetExplo rer.Application ")

ie.Navigate "c:\"
Do While ie.Busy Or ie.ReadyState<> 4
WScript.Sleep 100
Loop

Const ssfSENDTO=9 'ShellSpecialFo lderConstants.s sfSENDTO
Const ssfDESKTOP=0 ' ShellSpecialFol derConstants.ss fDESKTOP
ie.Document.App lication.NameSp ace(ssfDESKTOP) .Items().Item(a rchive).InvokeV erb
"copy"

Set oMapiMailItems =
ie.Document.App lication.NameSp ace(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

Apr 13 '07 #2
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\attach ment.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.File SystemObject" )

' seems a bug in the Guid method requires us to clip the returned
string
strGuid = Left(CreateObje ct("Scriptlet.T ypeLib").Guid, 38)

Set oWShell = CreateObject("W Script.Shell")
archive = fso.BuildPath(o WShell.ExpandEn vironmentString s("%TEMP%"), _
"MyEncrypto r_" & strGuid & ".fta" )

cmdline = "MyEncryptor.ex e -r -f " & archive & " -o " & """" &
WScript.Argumen ts(0) & """"

oWShell.Run cmdline,,True

Set ie=CreateObject ("InternetExplo rer.Application ")

ie.Navigate "c:\"
Do While ie.Busy Or ie.ReadyState<> 4
WScript.Sleep 100
Loop

Const ssfSENDTO=9 'ShellSpecialFo lderConstants.s sfSENDTO
Const ssfDESKTOP=0 ' ShellSpecialFol derConstants.ss fDESKTOP
ie.Document.App lication.NameSp ace(ssfDESKTOP) .Items().Item(a rchive).InvokeV erb
"copy"

Set oMapiMailItems =
ie.Document.App lication.NameSp ace(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/0...t-enail-trick/
--
Bits.Bytes
http://bytes.thinkersroom.com
Apr 14 '07 #3
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

On Apr 14, 12:15 am, "Rad [Visual C# MVP]" <nos...@nospam. comwrote:
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\attach ment.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.File SystemObject" )
' seems a bug in the Guid method requires us to clip the returned
string
strGuid = Left(CreateObje ct("Scriptlet.T ypeLib").Guid, 38)
Set oWShell = CreateObject("W Script.Shell")
archive = fso.BuildPath(o WShell.ExpandEn vironmentString s("%TEMP%"), _
"MyEncrypto r_" & strGuid & ".fta" )
cmdline = "MyEncryptor.ex e -r -f " & archive & " -o " & """" &
WScript.Argumen ts(0) & """"
oWShell.Run cmdline,,True
Set ie=CreateObject ("InternetExplo rer.Application ")
ie.Navigate "c:\"
Do While ie.Busy Or ie.ReadyState<> 4
WScript.Sleep 100
Loop
Const ssfSENDTO=9 'ShellSpecialFo lderConstants.s sfSENDTO
Const ssfDESKTOP=0 ' ShellSpecialFol derConstants.ss fDESKTOP
ie.Document.App lication.NameSp ace(ssfDESKTOP) .Items().Item(a rchive).InvokeV erb
"copy"
Set oMapiMailItems =
ie.Document.App lication.NameSp ace(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/0...t-enail-trick/
--
Bits.Byteshttp://bytes.thinkersr oom.com

Apr 16 '07 #4
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.Bytes
http://bytes.thinkersroom.com
Apr 16 '07 #5
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\attach ment.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

On Apr 16, 11:54 am, "Rad [Visual C# MVP]" <nos...@nospam. comwrote:
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.thinkersr oom.com

Apr 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2314
by: runningdog | last post by:
Hi Can someone point me to some documentation on how to create and send email from a win forms app using the defalt mail client TIA Steve
88
12556
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
3
5049
by: Ed Sutton | last post by:
How can I show the email client UI so the user can send the attachment to the desired recipient. I get an exception if I leave the MailMessage.To property blank. Is there any way to do this? I found a Microsoft example that uses mapi32.dll that can do this. But I can nopt make the SmtpMail work like I want. Thanks in advance, -Ed
7
10668
by: Darin | last post by:
Currently, our software is creating an email message using the Outlook DLL to send emails out that have PDF attachments. I want to stop forcing the customer to use outlook to send email. So, I know I can use "mailto" to send email, but what methodology should I use to send email using the default mail client WITH an attachment. Thanks Darin
2
10696
by: Landley | last post by:
Hello, Is there a way of creating an email, attaching a file and sending using the client's default mail client? I am looking for a none email client specific solution that does not involve specifying parameters such as mail servers etc. Cheers,
2
1808
by: KevinK | last post by:
Hi, Is there a way to let my Win forms application open my default mail client to send an email that the user still can modify? Thanks Kevin
2
32004
by: Hanika | last post by:
Going on 3 days and I am wodnering if I am just not looking in the right place. If anyone nows how to do this please please help me. I am developing a Windows form application using VB.NET 2005. I have a PDF file that I want to attach to the local default email client and display it so that the user can enter the rest of the information. Like one would see using the right-click Send To Mail Recipient. I tried using MailTo. But the...
2
1363
by: anshukher | last post by:
hi, i am making a windows application in C# and in that when i click on the send button the default mail client should open along with the attachment that i have browsed already! i have tried to do it by many ways, the dafault mail client(outlook 2003 in my case) does open up but the attachment that i have browsed does not open up as attachment in that! can u help my in this matter????
2
1731
beacon
by: beacon | last post by:
I have a DAP that I've added a command button to (and by default is set to be coded using vbscript, but I'll use whatever works). The command button uses the onclick method to look at a dropdown list, see if there's anything in it, and return a message as output to the monitor. This part works great. My main goal, however, is to get the script, once it's displayed the message on the screen, to open the default email client and start an email...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.