1

我有以下在 .Net 4.0 中构建的代码,它工作正常,但我现在必须在 .Net 3.5 中构建项目,并且在创建 MailItem 时出现错误。错误信息是:-

“'不能将类型'object'隐式转换为'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();

任何人都可以帮忙吗?我正在努力解决语法问题?

4

1 回答 1

2

Outlook.Application.CreateItem 返回一个对象(准确地说是动态的),您必须将其显式转换为 Outlook.MailItem,如下所示:

Outlook.MailItem mail = 
                application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
于 2012-09-20T10:07:35.787 回答