我有以下代码,我在.Net 4.0中构建,它工作正常,但我现在必须在.Net 3.5中构建项目,并且在创建MailItem时出现错误。错误消息是: -
“'无法将类型'对象'隐式转换为 'microsoft.office.interop.outlook.olmailitem'“
Outlook.Application application = new Outlook.Application();
Outlook.Folder folder =
application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts)
as Outlook.Folder;
Outlook.MailItem mail =
application.CreateItem(Outlook.OlItemType.olMailItem);
foreach (string name in addlist)
{
mail.Recipients.Add(name);
}
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mail.HTMLBody = msg;
mail.Subject = textBox1.Text;
mail.Save();
有人可以帮忙吗?我正在努力解决语法问题?
答案 0 :(得分:2)
Outlook.Application.CreateItem返回一个对象(动态,准确),你必须将它显式地转换为Outlook.MailItem,如下所示:
Outlook.MailItem mail =
application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;