WinForm下调用OutLook发送邮件(同理也能打开Skype)

某日,某项目中要做这样一个Winform,它要有一个这样的功能:即点击一个邮件地址link链接打开Outlook程序来发送邮件.

那么如何打开OutLook Express 来发邮件呢?
我作了如下的尝试
(1)、使用 System.Diagnostics.Process 来打开IE 使用参数 <a href=''mailto:test@msn.com'' class=''Email''>test@msn.com,即可打开,代码如下:
System.Diagnostics.ProcessStartInfo startInfo 
    = new System.Diagnostics.ProcessStartInfo("IExplore.exe", "mailto:test@msn.com");
System.Diagnostics.Process.Start(startInfo);

但问题是:此方法还打开了IE窗口。

后来又加了一句:
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

将IE窗口隐藏了,关闭发邮件的窗口却不能关闭IExplore进程。

(2)、经过查看发送邮件窗口的进程是 : msimn
直接使用 System.Diagnostics.Process 来打开 msimn.exe 却是找开 outLook Express 界面,看来此路也行不通。

(3)、后来查到可以使用 Win API 平台调用来实现,所以使用如下的方法来解决:
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
     );
}

在按钮事件中使用:
Win32.ShellExecute(0, String.Empty, "mailto:test@msn.com", String.Empty, String.Empty, 1);

这样就完成了此需求,不知道还有别的方法呢。

PS:我们也能用这样的方法打开Skype程序,直接呼叫客户.

posted @ 2011-05-23 16:49  铁芒阁  阅读(1190)  评论(0编辑  收藏  举报
分享到: