C how to open email software

  • 2020-05-24 06:02:23
  • OfStack

Open the specified URL using the client
Use the Process.Start method to open the specified URL in a browser. The code is shown below.

[C#]
/ / using the client to open the "https: / / www. ofstack. com" System. Diagnostics. Process. Start (www. ofstack. com);
Open the email software
You can also open the E-mail software (Mail) using the Process.Start method.

The code below is an example of opening Mail to send a message to email address lxc880615@163.com.

[C#]
/ / open the mail client set "To" to "lxc880615@163.com" System Diagnostics. Process. Start (" mailto: lxc880615@163.com ");
Added: "mailto:lxc880615@163.com" and "mailto:? to = lxc880615@163.com "1 sample.

Specify the E-mail address for the plural
Use commas to specify plural email addresses, as described in RFC2368.

The following code is an example of specifying "test1@sample.com" and "test2@sample.com".

[C#]


System.Diagnostics.Process.Start("mailto:test1@sample.com,test2@sample.com"); Specify the topic, content, CC , BCC

You can also specify topics, content, and so on using the Process.Start method. The following code is an example of specifying a topic as "hello."

[C#]


System.Diagnostics.Process.Start("mailto:lxc880615@163.com?subject= How do you do "); And the method above 1 The following code is to specify the content, CC , BCC In the example. 

[C#]


// Send the address 
string to = " lxc880615@163.com"; 
// The theme  
string subject = " How do you do "; 
// content  
string body = " Welcome to luo xucheng. "; //
CC string cc = "cc@163.com";//
BCC string bcc = "bcc@163.com"; // Open the standard mail client  System.Diagnostics.Process.Start( string.Format("mailto:{0}?subject={1}&body={2}&cc={3}&bcc={4}", to, subject, body, cc, bcc)); Text appears in both the subject and the content in the code above, 1 There are no errors, but if" & "," = ", change the line of text will occur when the error, then need to carry on the coding setting. 

The following code is an example of modifying the above code using URL encoding. Because you need to use the HttpUtility method, you must append System.Web.dll to the reference. See here for a detailed description of the Encoding class specified by the encoding method.

[C#]


System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
// Send the address  
string to = "lxc880615@163.com "; 
// The theme  
string subject = " How do you do "; 
subject = System.Web.HttpUtility.UrlEncode(subject, enc); 
// content 
string body = " Luo Xucheng \r\n You are welcome "; 
body = System.Web.HttpUtility.UrlEncode(body, enc);//
CC string cc = "cc@163.om"; //
BCC string bcc = "bcc@163.com "; 
// Open the standard software client 
 System.Diagnostics.Process.Start( string.Format("mailto:{0}?subject={1}&body={2}&cc={3}&bcc={4}", to, subject, body, cc, bcc));


Related articles: