这可能是非常初学者的问题。我正在尝试创建我的第一个 Windows 窗体应用程序,并希望通过单击窗体上的按钮来创建 Outlook 电子邮件。
问题是有13个错误主要是说:
严重性代码描述项目文件行抑制状态错误 CS0246 找不到类型或命名空间名称“Outlook”(您是否缺少 using 指令或程序集引用?)提供机器 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("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());
}
}
private void Label1_Click(object sender, EventArgs e)
{
}
}
}