如何打开Outlook新邮件窗口c#
我正在寻找一种方式来在Outlook窗口中打开新邮件。如何打开Outlook新邮件窗口c#
我需要programically填写:从,到,主题,正文信息,但离开这个新邮件窗口中打开,以便用户可以验证内容/添加一些东西然后把正常的Outlook味精。
发现:
Process.Start(String.Format(
"mailto:{0}?subject={1}&cc={2}&bcc={3}&body={4}",
address, subject, cc, bcc, body))
但没有 “从” 选项(我的用户有多个邮箱的详细......)
任何意见(S)?
I'cve终于解决了这个问题 下面是一段代码,解决我的问题(与使用的Outlook互操作性展示)
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem (Outlook.OlItemType.olMailItem);
oMailItem.To = address;
// body, bcc etc...
oMailItem.Display (true);
使用此代码我得到一个例外。 – papaiatis 2013-03-27 13:30:05
谢谢,效果很好。 – mack 2013-07-05 18:39:50
当我的Outlook没有打开时,当我运行类似的东西时,Outlook会打开,我会看到模态电子邮件对话框,但只要用户点击发送并且电子邮件停留在发件箱中,Outlook就立即关闭。有没有人有这个问题? – user1198049 2013-09-04 22:17:12
你不能用mailto做到这一点。您的客户必须选择他们发送的帐户,默认帐户为默认帐户,或者您必须提供邮件表单并在发送电子邮件时设置标题。
我知道我做不到这一点 - 这就是为什么我看着不同的选择 - 看到一些应用程序管理,所以必须以某种方式... – Maciej 2011-05-27 07:39:13
这是我都试过了。它按预期工作。
此应用程序添加收件人,添加cc并添加主题并打开一个新的邮件窗口。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using Outlook = Microsoft.Office.Interop.Outlook;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSendMail_Click(object sender, EventArgs e)
{
try
{
List<string> lstAllRecipients = new List<string>();
//Below is hardcoded - can be replaced with db data
lstAllRecipients.Add("[email protected]");
lstAllRecipients.Add("[email protected]");
Outlook.Application outlookApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector = oMailItem.GetInspector;
// Thread.Sleep(10000);
// Recipient
Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
foreach (String recipient in lstAllRecipients)
{
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
oRecip.Resolve();
}
//Add CC
Outlook.Recipient oCCRecip = oRecips.Add("[email protected]");
oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
oCCRecip.Resolve();
//Add Subject
oMailItem.Subject = "Test Mail";
// body, bcc etc...
//Display the mailbox
oMailItem.Display(true);
}
catch (Exception objEx)
{
Response.Write(objEx.ToString());
}
}
}
如果用户使用outlook取消按钮取消发送电子邮件,您将如何取消发送电子邮件? – singhswat 2017-04-13 11:57:38
该代码只会生成一个新的电子邮件窗口,其中填充了To:和Subject字段并将其显示。用户可以发送电子邮件(或不发送),所以如果电子邮件窗口关闭(未发送),则不会发送电子邮件。 – 2017-09-03 17:36:07
是否有一个原因,你没有在Outlook本身的应用程序使用VBScript?最终,如果你愿意,你可以很容易地从c#启动Outlook应用程序,在启动时运行的outlook中有一个规则,可以从vbscript宏为你填充。正如你期望在gui中编辑它,我的问题依然存在:你需要一个特定于c#的解决方案吗?或者你只是在问你是否需要使用c#? – tjborromeo 2013-05-01 00:08:14