簡體   English   中英

如何打開 Outlook 新郵件 window c#

[英]How to open Outlook new mail window c#

我正在尋找一種在 Outlook window 中打開新郵件的方法。

我需要以編程方式填寫:從、到、主題、正文信息,但將這個新郵件 window 保持打開狀態,以便用戶可以驗證內容/添加內容,然后正常發送 Outlook 消息。

發現:

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

但是沒有“發件人”選項(我的用戶有多個郵箱...)

有什么建議嗎?

我終於解決了這個問題。 這是解決我的問題的一段代碼(使用 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 );

這是我嘗試過的。 它按預期工作。

此應用程序添加收件人,添加抄送並添加主題並打開新郵件 window。

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());
        }
    }
}

你不能用 mailto 做到這一點。 您的客戶要么必須 select 他們發送的帳戶,默認為他們的默認帳戶,要么您必須在發送電子郵件時提供郵件表單並設置標題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM