email client

J

jake

In Windows Forms, how do I bring up the default email client so the
user can enter a new message? Also, how do I pre-populate the "To,"
"From" and the "Subject" boxes?
Your help is greatly appreciated.
jake
 
P

Peter Duniho

In Windows Forms, how do I bring up the default email client so the
user can enter a new message? Also, how do I pre-populate the "To,"
"From" and the "Subject" boxes?

Well, it's not really about "in Windows Forms". There's no specific
support in the System.Windows.Forms namespace, that is.

But, I believe (haven't tested) that you can probably accomplish this
simply by using the Process class. Make sure that you leave the
ProcessStartInfo.UseShellExecute property set to "true" (that's the
default), and then provide a "mailto:" scheme string
(http://www.faqs.org/rfcs/rfc2368.html). Windows should then map that to
the appropriate thing.

Pete
 
J

Jeff Gaines

In Windows Forms, how do I bring up the default email client so the
user can enter a new message? Also, how do I pre-populate the "To,"
"From" and the "Subject" boxes?
Your help is greatly appreciated.
jake

I have a library function which may help:

public static void SendEmail(string emailAddress, string emailSubject,
string emailBody)
{
Process newProc = new Process();
string email = "mailto:" + emailAddress + "?subject=" + emailSubject +
"&body=" + emailBody;
newProc.StartInfo.FileName = email;
newProc.Start();
}
 
C

con-man-jake

I have a library function which may help:

public static void SendEmail(string emailAddress, string emailSubject,
string emailBody)
{
        Process newProc = new Process();
        string email = "mailto:" + emailAddress + "?subject="+ emailSubject +
"&body=" + emailBody;
        newProc.StartInfo.FileName = email;
        newProc.Start();

}

Hi Peter,
My query was geared towards finding which application serves as a mail
client on the machine. I can, then, easily start it using, of course,
the Process class. Any library/namespace will do fine as long as it
does the job. I wanted to find something as easy and as straight-
forward as using the HTML's "mailto:" option in an Anchor's href,
whereby the browser itself can find the mail client, start it, and pre-
populate the "To:" field.
At any rate, your link gives me valuable info to use in another
application I am currently building, coincidentaly.

Jeff,
I will give it a world...but I am a little hazy on how would one
determine what exe-file to start. In other words; what is the "email"
in "newProc.StartInfo.FileName = email;"

In going through an internet search, I came up with

Registry.ClassesRoot
.OpenSubKey("mailto")
.OpenSubKey("shell")
.OpenSubKey("open")
.OpenSubKey("command")

With additions to make it a string and strip away any double quotes
and put in email fields syntax...using ToString() and Replace() and
what have you...

This is giving me some little problems, which I will get straightened
out in time.

I was kind-of hoping to be shielded from all of that, and just use a
library method from somewhere in the annals of .Net. But I guess I
have to put some elbow grease into this.

Thanks to both of you,
If you think of something else, please let me know.
jake
 
J

Jeff Gaines

I will give it a world...but I am a little hazy on how would one
determine what exe-file to start. In other words; what is the "email"
in "newProc.StartInfo.FileName = email;"

You don't need to worry about that. 'email' is a string and in the next 2
lines:

newProc.StartInfo.FileName = email;
newProc.Start();

Windows will automagically start the default email program.
 
C

con-man-jake

Hi Peter,
My query was geared towards finding which application serves as a mail
client on the machine. I can, then, easily start it using, of course,
the Process class.  Any library/namespace will do fine as long as it
does the job.  I wanted to find something as easy and as straight-
forward as using the HTML's "mailto:" option in an Anchor's href,
whereby the browser itself can find the mail client, start it, and pre-
populate the "To:" field.
At any rate, your link gives me valuable info to use in another
application I am currently building, coincidentaly.

Jeff,
I will give it a world...but I am a little hazy on how would one
determine what exe-file to start.  In other words; what is the "email"
in "newProc.StartInfo.FileName = email;"

In going through an internet search, I came up with

Registry.ClassesRoot
            .OpenSubKey("mailto")
            .OpenSubKey("shell")
            .OpenSubKey("open")
            .OpenSubKey("command")

With additions to make it a string and strip away any double quotes
and put in email fields syntax...using ToString() and Replace() and
what have you...

This is giving me some little problems, which I will get straightened
out in time.

I was kind-of hoping to be shielded from all of that, and just use a
library method from somewhere in the annals of .Net.  But I guess I
have to put some elbow grease into this.

Thanks to both of you,
If you think of something else, please let me know.
jake

Peter,
My sincere apologies. Your post did solve my problem. I just had to
pay closer attention.
Cheers,
jake
 
C

con-man-jake

You don't need to worry about that. 'email' is a string and in the next 2
lines:

newProc.StartInfo.FileName = email;
newProc.Start();

Windows will automagically start the default email program.

Jeff,
"Windows will automagically start the default email program." That's
what I found out just before I posted my apology to Peter. With a
simple:
Process.Start("mailto:[email protected]");
the default email client message compose window came up. I will now
add more mailto syntax to pre-populate other fields.
Thank you very much for yours and Peter's help.
Regards,
jake
 

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