Friday, August 5, 2011

Launching the Default Email Client

I was asked to write some code to send an email through the default email client and I was pleasantly surprised as to how easy it was to do. I had never done this before, so it was a learning experience for me, so I thought I’d share it with all of you.

string toEmail = "from@email.com";
string subject = "Test Subject";
string body = "test email message text";
string message =
string.Format("mailto:{0}?subject={1}&body={2}",toEmail, subject, body);
Process.Start(message);

So that should do it. It’s pretty simple. When you run this code, you should see the default email client launch with the appropriate fields filled in.

Cheers!

No comments:

Post a Comment