34

我正在寻找一种在 Outlook 窗口中打开新邮件的方法。

我需要以编程方式填写:发件人、收件人、主题、正文信息,但让这个新邮件窗口保持打开状态,以便用户可以验证内容/添加内容,然后像普通 Outlook 消息一样发送。

发现:

Process.Start(String.Format(
 "mailto:{0}?subject={1}&cc={2}&bcc={3}&body={4}", 
  address, subject, cc, bcc, body))

但是没有“发件人”选项(我的用户有多个邮箱...)

有什么建议吗?

4

3 回答 3

55

我终于解决了这个问题。这是解决我的问题的一段代码(使用 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 );
于 2011-05-29T05:32:55.700 回答
10

这是我尝试过的。它按预期工作。

此应用程序添加收件人,添加抄送和添加主题并打开一个新的邮件窗口。

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("sanjeev.kumar@testmail.com");
            lstAllRecipients.Add("chandan.kumarpanda@testmail.com");

            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("THIYAGARAJAN.DURAIRAJAN@testmail.com");
            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());
        }
    }
}
于 2015-01-07T14:11:57.183 回答
-1

你不能用 mailto 做到这一点。您的客户必须选择他们发送邮件的帐户,默认为他们的默认帐户,或者您必须在发送电子邮件时提供邮件表单并设置标题。

于 2011-05-27T06:50:33.743 回答