Send an email through the Outlook email client from vb.net

M

Markei54545

Hi all,

I would like to be able to launch the Outlook 'Compose email' screen
from my vb.net 2005 program, and include an attachment.

Version of Outlook is 2007 and is installed on the clients machine.

Any ideas how I would achieve this?

Thanks

Mark
 
O

Onur Güzel

Hi all,

I would like to be able to launch the Outlook 'Compose email' screen
from my vb.net 2005 program, and include an attachment.

Version of Outlook is 2007 and is installed on the clients machine.

Any ideas how I would achieve this?

Thanks

Mark

Untested in 2007, it my work with outlook 2003, but you can try:

Process.Start("mailto:[email protected]?Attachment=""C:
\yourfile.mp3""")

HTH,

Onur
 
S

StrandElectric

Hi all,

I would like to be able to launch the Outlook 'Compose email' screen
from my vb.net 2005 program, and include an attachment.

Version of Outlook is 2007 and is installed on the clients machine.

Any ideas how I would achieve this?

Thanks

Mark

Untested in 2007, it my work with outlook 2003, but you can try:

Process.Start("mailto:[email protected]?Attachment=""C:
\yourfile.mp3""")

HTH,

Onur

That is a delightfully simple piece of code Onur! I have been experimenting
with filling in the subject and the body text, without success (using
Outlook 2000). Also cannot see a simple way of signalling an error if the
file to be attached is not there.
 
T

Tom Shelton

Markei54545 expressed precisely :
Hi all,

I would like to be able to launch the Outlook 'Compose email' screen
from my vb.net 2005 program, and include an attachment.

Version of Outlook is 2007 and is installed on the clients machine.

Any ideas how I would achieve this?

Thanks

Mark

Is there a particular reason you want to launch the outlook client? I
personally find it easier to use System.Net.Mail.SmtpClient class...
 
A

Andrew Morton

StrandElectric said:
Untested in 2007, it my work with outlook 2003, but you can try:

Process.Start("mailto:[email protected]?Attachment=""C:
\yourfile.mp3""")


That is a delightfully simple piece of code Onur! I have been
experimenting with filling in the subject and the body text, without
success (using Outlook 2000). Also cannot see a simple way of
signalling an error if the file to be attached is not there.

You could check if the file is there before trying to attach it...

Dim somefile As String="C:\yourfile.mp3"
If File.Exists(somefile) Then
Process.Start...
Else
' Alert user to missing file
End If
 
M

Markei54545

Hi,

I was looking for something that actually displayed the email client
so that the user could make changes etc.

Many thanks

Mark
 
J

Jason Keats

Tom said:
Markei54545 expressed precisely :

Is there a particular reason you want to launch the outlook client? I
personally find it easier to use System.Net.Mail.SmtpClient class...

The usual reason for wanting to send via the users email client is so
the outgoing message is stored in their sent box (or other Exchange
folder) - and can be archived, searched, etc., along with the rest of
their email. The easiest/best way of doing this is via Outlook
Redemption: http://www.dimastr.com/redemption/

It's much easier than trying to manage copies of sent messages when
using System.Net.Mail - although BCCing the sender might be an
acceptable way around that requirement.
 
T

Tom Shelton

After serious thinking Jason Keats wrote :
The usual reason for wanting to send via the users email client is so the
outgoing message is stored in their sent box (or other Exchange folder) - and
can be archived, searched, etc., along with the rest of their email. The
easiest/best way of doing this is via Outlook Redemption:
http://www.dimastr.com/redemption/

It's much easier than trying to manage copies of sent messages when using
System.Net.Mail - although BCCing the sender might be an acceptable way
around that requirement.

You maybe correct - but, I prefere to understand the OP's requirement.
To often, the problem is simply "I need to send an email with an
attachment" and the questioner has only assumed that they must automate
outlook to do so....
 
O

Onur Güzel

Untested in 2007, it my work with outlook 2003, but you can try:

Process.Start("mailto:[email protected]?Attachment=""C:
\yourfile.mp3""")

HTH,

Onur

That is a delightfully simple piece of code Onur!  I have been experimenting
with filling in the subject and the body text, without success (using
Outlook 2000). Also cannot see a simple way of signalling an error if the
file to be attached is not there.

Attachment syntax in mailto protocol is experimental because AFAIK
attachment(s) are not officially a part of mailto protocol as RFC
statements imply. So there are custom implementations on this like
that:

http://www.codeproject.com/KB/IP/SendTo.aspx

However, I saw some people succeeded attaching files like here:
http://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx

and like here:
http://stackoverflow.com/questions/1195111/c-mailto-with-attachment

Though, if you want to check the file exists just before attaching it,
as Andrew pointed, you can always use File.Exists to determine.

HTH,

Onur
 
S

StrandElectric

Untested in 2007, it my work with outlook 2003, but you can try:

Process.Start("mailto:[email protected]?Attachment=""C:
\yourfile.mp3""")

HTH,

Onur

That is a delightfully simple piece of code Onur! I have been
experimenting
with filling in the subject and the body text, without success (using
Outlook 2000). Also cannot see a simple way of signalling an error if the
file to be attached is not there.

Attachment syntax in mailto protocol is experimental because AFAIK
attachment(s) are not officially a part of mailto protocol as RFC
statements imply. So there are custom implementations on this like
that:

http://www.codeproject.com/KB/IP/SendTo.aspx

However, I saw some people succeeded attaching files like here:
http://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx

and like here:
http://stackoverflow.com/questions/1195111/c-mailto-with-attachment

Though, if you want to check the file exists just before attaching it,
as Andrew pointed, you can always use File.Exists to determine.

HTH,

Onur

But any takers for the subject field and body? Suppose for example that I
want to send an email to (e-mail address removed) and say in the subject line
"Help required" and then in the message body "User has pressed personal help
button on form no. "&FormNo... (FormNo of course being a variable passed
from a program).
 
C

Cor

Yea then the first reply from Luuk matches in my opinion the most as answer
to your problem.

Be aware that it needs the by you used Office Outlook as client on the
clients computers.

Like is written does the default mail client protocol not support
attachments

The MSFT server does not open a client.

Success

Cor

"Markei54545" wrote in message

Hi,

I was looking for something that actually displayed the email client
so that the user could make changes etc.

Many thanks

Mark
 
O

Onur Güzel

Attachment syntax in mailto protocol is experimental because AFAIK
attachment(s) are not officially a part of mailto protocol as RFC
statements imply. So there are custom implementations on this like
that:

http://www.codeproject.com/KB/IP/SendTo.aspx

However, I saw some people succeeded attaching files like here:http://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx

and like here:http://stackoverflow.com/questions/1195111/c-mailto-with-attachment

Though, if you want to check the file exists just before attaching it,
as Andrew pointed, you can always use File.Exists to determine.

HTH,

Onur

But any takers for the subject field and body?  Suppose for example that I
want to send an email to (e-mail address removed)  and say in the subject line
"Help required" and then in the message body "User has pressed personal help
button on form no. "&FormNo...   (FormNo of course being a variable passed
from a program).

Subject and body fields of course, are available in mailto like this:
Process.Start("mailto:[email protected]?subject=hello&body=something")

I just tried sampling attachment field if it works for OP.

Onur
 
S

StrandElectric

Attachment syntax in mailto protocol is experimental because AFAIK
attachment(s) are not officially a part of mailto protocol as RFC
statements imply. So there are custom implementations on this like
that:

http://www.codeproject.com/KB/IP/SendTo.aspx

However, I saw some people succeeded attaching files like
here:http://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx

and like
here:http://stackoverflow.com/questions/1195111/c-mailto-with-attachment

Though, if you want to check the file exists just before attaching it,
as Andrew pointed, you can always use File.Exists to determine.

HTH,

Onur

But any takers for the subject field and body? Suppose for example that I
want to send an email to (e-mail address removed) and say in the subject line
"Help required" and then in the message body "User has pressed personal
help
button on form no. "&FormNo... (FormNo of course being a variable passed
from a program).

Subject and body fields of course, are available in mailto like this:
Process.Start("mailto:[email protected]?subject=hello&body=something")

Onur

OK, got this. But note that hello and something are literals but are not
enclosed in quotes. I would lke to pass a variable. eg, for subject I would
like ThisSubject, having specified it, but if I do that by Dim ThisSubject =
"Bloggins" then I don't get Bloggins in the subject line; I get ThisSubject!
How to get around that?
 
O

Onur Güzel

Subject and body fields of course, are available in mailto like this:
Process.Start("mailto:[email protected]?subject=hello&body=something")

Onur

OK, got this. But note that hello and something are literals but are not
enclosed in quotes. I would lke to pass a variable. eg, for subject I would
like ThisSubject, having specified it, but if I do that by Dim ThisSubject =
"Bloggins" then I don't get Bloggins in the subject line; I get ThisSubject!
How to get around that?


It's nothing more than a basic string concatenation. Just do it like
this:

Dim ThisSubject = "Bloggins"
Dim thisbody = "something_here"
Process.Start("mailto:[email protected]?subject=" + ThisSubject + _
"&body=" + thisbody)

HTH,

Onur
 
S

StrandElectric

Onur Güzel said:
It's nothing more than a basic string concatenation. Just do it like
this:

Dim ThisSubject = "Bloggins"
Dim thisbody = "something_here"
Process.Start("mailto:[email protected]?subject=" + ThisSubject + _
"&body=" + thisbody)

HTH,

Onur

Certainly does! Works a treat. Pity Outlook 2000 (which I use) apparently
does not allow attachments! Seems to me that this an ideal way of keeping
tabs on licenced software, ie "User .... accessed my program... on....'' or
providing a "help" button in a program.
 
S

StrandElectric

StrandElectric said:
Certainly does! Works a treat. Pity Outlook 2000 (which I use) apparently
does not allow attachments! Seems to me that this an ideal way of keeping
tabs on licenced software, ie "User .... accessed my program... on....''
or providing a "help" button in a program.
Replying to own post after a moment's thought: It would not do as a licence
checker because the mail client (mine does anyway) would ask for the user to
confirm/spell check etc. However, might be a useful 'help' route (if the
author did not mind umpteen queries night and day!)
 
T

Tom Shelton

StrandElectric has brought this to us :
Replying to own post after a moment's thought: It would not do as a licence
checker because the mail client (mine does anyway) would ask for the user to
confirm/spell check etc. However, might be a useful 'help' route (if the
author did not mind umpteen queries night and day!)

Or you could just use system.net.smtpclient...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top