如何使用用户的默认电子邮件客户端弹出撰写/创建邮件对话框? [英] How do I popup the compose / create mail dialog using the user's default email client?

查看:159
本文介绍了如何使用用户的默认电子邮件客户端弹出撰写/创建邮件对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例很简单。在某个时间点,我需要能够向用户展示他熟悉的撰写电子邮件对话框(Outlook或其他)与




  • 字段

  • 电子邮件也将附有附件。



邮件不应该被发送,除非用户明确表示支持。



我曾经在这个VB6天做了这个。 。不知道现在如何..我只记得这是很容易的。



管理的应用程序,C#,.net 3.0 +



更新#1 :是的,似乎邮件删除对附件的支持(作为安全风险?)。我试过



您需要包含ShellExecute签名如这里所述。所有我从这里得到的是一个5 SE_ERR_ACCESSDENIED 和一个2仅为一些品种

  string sMailToLink = @mailto:some.address@gmail.com?subject =嘿& body =是的是啊是啊 
IntPtr result = ShellExecute(IntPtr.Zero,open,sMailToLink,,,ShowCommands.SW_SHOWNORMAL);
Debug.Assert(result.ToInt32()> 32,Shell Execute failed with return code+ result.ToInt32());

同样的MailtoLink可以与Process.Start ...但是完全相同,只要你没有提到附件

  System.Diagnostics.Process.Start(sMailToLink); 

其他选项是使用Outlook对象模型来做到这一点..但是我被告知这需要您根据安装的Outlook的确切版本添加程序集引用。如果用户不喜欢MS用于电子邮件,这也将会爆炸。



下一个选项是Mapi和一些名为 Mapi33 ..状态仍然在进度。您可以创建一个流程对象,并将其称为mailto:user@example.com。主题=我+新+主题。这将导致系统使用其默认处理程序对mailto进行操作,但是您可以设置主题,因此不会处理添加附件。我会自由地承认我不完全确定你如何去强制一个附件,而不用写一些邮件插件。



流程代码是:

  System.Diagnostics.Process.Start(mailto:user@example.com?subject = My + New + Subject); 


The use case is simple. At a certain point of time, I need to be able to show the user his familiar compose email dialog (Outlook or other) with

  • fields like from, to, Subject already filled up with certain application determined values.
  • The email would also have an attachment along with it.

The mail should not be sent unless the user explicitly okays it.

I did this once back in the ol' VB6 days.. can't figure out how now.. I just remember that it was quite easy.

Managed app, C#, .net 3.0+

Update#1: Yeah seems like mailto removed support for attachments (as a security risk?). I tried

You need to include ShellExecute signature as described here. All I got from this was a 5 SE_ERR_ACCESSDENIED and a 2 just for some variety

string sMailToLink = @"mailto:some.address@gmail.com?subject=Hey&body= yeah yeah yeah";
IntPtr result = ShellExecute(IntPtr.Zero, "open", sMailToLink, "", "", ShowCommands.SW_SHOWNORMAL);
Debug.Assert(result.ToInt32() > 32, "Shell Execute failed with return code " + result.ToInt32());

The same MailtoLink works perfectly with Process.Start... but as long as thou shalt not mention attachments.

System.Diagnostics.Process.Start(sMailToLink);

The other options are using the Outlook Object model to do this.. but I've been told that this requires you to add assembly references based to the exact version of Outlook installed. Also this would blow up if the user doesn't prefer MS for email.

The next option are Mapi and something called Mapi33.. Status still IN PROGRESS. Ears still open to suggestions.

解决方案

You can create a process object and have it call "mailto:user@example.com?subject=My+New+Subject". This will cause the system to act on the mailto with its default handler, however, while you can set subjects and such this wont handle adding an attachment. I'll freely admit im not entirely sure how you'd go about forcing an attachment without writing some mail plugin.

The process code is:

System.Diagnostics.Process.Start("mailto:user@example.com?subject=My+New+Subject");

这篇关于如何使用用户的默认电子邮件客户端弹出撰写/创建邮件对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆