亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Windows 窗體創建新的 Outlook 電子郵件

使用 Windows 窗體創建新的 Outlook 電子郵件

C#
狐的傳說 2023-09-09 16:27:44
這可能是非常初學者的問題。我正在嘗試創建我的第一個 Windows 窗體應用程序,并希望通過單擊窗體上的按鈕來創建 Outlook 電子郵件。問題是有13個錯誤,主要是:嚴重性代碼 說明 項目文件行抑制狀態錯誤 CS0246 找不到類型或命名空間名稱“Outlook”(是否缺少 using 指令或程序集引用?) Offer machine v.0.0.1 C:\Users\PC\source \repos\Offer machine v.0.0.1\Offer machine v.0.0.1\Form1.cs 29 活動我已經添加了對我的項目的引用:這是代碼:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Offer_machine_v._0._0._1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Button1_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();                }    }}
查看完整描述

2 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

您沒有在代碼中添加正確的使用。您需要添加:


using Microsoft.Office.Interop.Outlook;

如果沒有這一行,您應該在互操作庫中的每個對象之前鍵入完整的命名空間。使用到位后,您可以刪除來Outlook.自互操作的所有對象。但是創建主 Application 對象需要完整的命名空間,以避免與 Winforms 中定義的 Application 類發生沖突。


Microsoft.Office.Interop.Outlook.Application outlookApp = 

                   new Microsoft.Office.Interop.Outlook.Application();

_MailItem oMailItem = (_MailItem)outlookApp.CreateItem(OlItemType.olMailItem);

Inspector oInspector = oMailItem.GetInspector;


..... and so on ....


查看完整回答
反對 回復 2023-09-09
?
桃花長相依

TA貢獻1860條經驗 獲得超8個贊

您似乎已將 Outlook 互操作添加到項目引用中兩次。

https://img4.sycdn.imooc.com/64fc2ccd0001260f03440749.jpg

至于錯誤信息,你只需要在 Outlook 命名空間中添加一個別名即可:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


using Outlook = Microsoft.Office.Interop.Outlook;

using Office = Microsoft.Office.Core;

此外,您可能會發現C# 應用程序自動化 Outlook (CSAutomateOutlook)示例項目很有幫助。



查看完整回答
反對 回復 2023-09-09
  • 2 回答
  • 0 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號