Send emails by calling outlook in winform

Source: Internet
Author: User

In today's project, we need to do this: click a button to open the mail window.
According to the project requirements, you do not need to implement the mail function by yourself. You only need to call the system's mail function.

How can I enable Outlook Express to send emails?
I tried the following:
(1), use system. Diagnostics. process to open ie using the parameter mailto: dingo_zgl@msn.com, you can open,CodeAs follows:

System. Diagnostics. processstartinfo startinfo =   New System. Diagnostics. processstartinfo ( " Iexplore.exe " , " Mailto: dingo_zgl@msn.com " );
System. Diagnostics. process. Start (startinfo );

But the problem is: This method opens the IE window.

Then I added the following sentence:

Startinfo. windowstyle = System. Diagnostics. processwindowstyle. hidden;

The IE window is hidden, but the iexplore process cannot be closed when the mail window is closed.

(2) The process of viewing the sending mail window is: msimn
You can directly use system. Diagnostics. process to open msimn.exe but find the Outlook Express interface. It does not seem feasible.

(3) later, we found that we can use the win api platform to call this function. Therefore, we should use the following methods to solve the problem:

  Public   Class Win32
  {
[Dllimport ( " Shell32.dll " , Entrypoint = " Shellexecutea " )]
Public   Static   Extern   Int ShellExecute (
Int Hwnd,
String lpoperation,
String lpfile,
String lpparameters,
String lpdirectory,
Int Nshowcmd
);
}

Use in button events:

Win32.shellexecute ( 0 , String. empty, " Mailto: dingo_zgl@msn.com " , String. Empty, String. empty, 1 );

This requirement has been fulfilled.

Do you know what other good methods do you have? I also started to develop. net. Please give me more advice!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.