Friday, August 27, 2010

Open Standard Email Program

In the previous post I showed, how to open an URL with the standard browser. Today's post is about opening an email draft with the standard email client.
Again, System.Diagnostics.Process.Start() gives us the desired success. This time, a "mailto:" has to be put in front of the parameter, just like in hyperlinks for writing emails.
The syntax is the same as that of the HTML - Mailto: After "mailto" the address of the recceiver is expected, additionally further parameters can be appended. The first one is split by a question mark ("?") from the receiver address, the others by "&".
The following parameters are possible:
  • cc: Carbon Copy, a copy of the mail is sent to this address, the first receiver sees this.
  • bcc: Blind Carbon Copy, a copy of the mail is sent to this address, the first receiver does not see this.
  • subject: Subject of the message.
  • body: Content of the message.
By the string "%0A" a new line can be inserted in the body.
But attention: Not all email clients support all of these parameters.
The following example opens a window of the standard email program with a message to me:
System.Diagnostics.Process.Start("mailto:bloggeroliver@web.de");

The next command opens a new email window, for which all parameters described above are used:
System.Diagnostics.Process.Start("mailto:bloggeroliver@web.de?bcc=bloggeroliver@web.de&cc=bloggeroliver@web.de&subject=Testmail&body=Hello Oliver,%0Athis mail was created by your sample application.");

No comments:

Post a Comment