Microsoft Visual Studio 中的引用不起作用 [英] References in Microsoft Visual Studio not working

查看:65
本文介绍了Microsoft Visual Studio 中的引用不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在尝试使用 VB.NET 发送电子邮件.现在,我添加了此代码的引用:(我添加了占位符)

Currently, I am attempting to send an email using VB.NET. Now, I have added a reference with this code: (I have added placeholders)

Module Module1

    Sub Main()
        ' Create an Outlook application.
        Dim oApp As Outlook._Application
        oApp = New Outlook.Application()

        ' Create a new MailItem.
        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"
        oMsg.Body = "Hello World" & vbCr & vbCr

        ' TODO: Replace with a valid e-mail address.
        oMsg.To = "user@example.com"

        ' Add an attachment
        ' TODO: Replace with a valid attachment path.
        Dim sSource As String = "C:\Temp\Hello.txt"
        ' TODO: Replace with attachment name
        Dim sDisplayName As String = "Hello.txt"

        Dim sBodyLen As String = oMsg.Body.Length
        Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim oAttach As Outlook.Attachment
        oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)

        ' Send
        oMsg.Send()

        ' Clean up
        oApp = Nothing
        oMsg = Nothing
        oAttach = Nothing
        oAttachs = Nothing
    End Sub

End Module

对于所有未声明或未定义的 Outlook 项目(Outlook.Application、Outlook._MailItem、Outlook、Outlook.Attachments、Outlook.Attachment),我如何才能使引用起作用.

How can I get the references to work, for all of the Outlook items (Outlook.Application, Outlook._MailItem, Outlook, Outlook.Attachments, Outlook.Attachment) are either undeclared or undefined.

提前致谢.

推荐答案

添加对Microsoft Outlook 11.0 对象库"的引用:

Add a reference to the "Microsoft Outlook 11.0 Object Library":

  1. 在项目"菜单上,单击添加引用".
  2. 在 COM 选项卡上,单击 Microsoft Outlook 11.0 对象库,然后单击选择.
  3. 在添加引用"对话框中单击确定"以接受您的选择.如果系统提示您为所选库生成包装器,请单击是".

在代码中你必须添加:

Imports Outlook = Microsoft.Office.Interop.Outlook

在此处找到更多信息:Handy Tasks UsingMicrosoft Office Outlook 2003 和 Visual Basic .NET

但如果您使用 .NET,为什么不使用 System.Net.Mail?

But if you're in .NET, why not use System.Net.Mail?

这篇关于Microsoft Visual Studio 中的引用不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆