Microsoft Visual Studio 中的引用不起作用

发布于 2024-11-18 19:34:11 字数 1492 浏览 1 评论 0原文

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

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 = "[email protected]"

        ' 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)的引用正常工作) 要么是未声明的,要么是未定义的。

提前致谢。

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 = "[email protected]"

        ' 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

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.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怂人 2024-11-25 19:34:11

在“解决方案资源管理器”中,右键单击您的项目并选择“添加引用”,然后向下滚动,直到看到 Microsoft.Office.Interop.Outlook 并选择该项目。然后在 VB 文件顶部添加“Imports Microsoft.Office.Interop”。

In Solution Explorer right click on your project and select "Add Reference" and scroll down until you see Microsoft.Office.Interop.Outlook and select that one. Then add "Imports Microsoft.Office.Interop" at the top of your VB file.

回眸一笑 2024-11-25 19:34:11

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

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

在代码中,您必须添加以下内容:

Imports Outlook = Microsoft.Office.Interop.Outlook

此处找到更多信息:使用 Microsoft Office Outlook 2003 和 Visual Basic .NET 的便捷任务

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

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

  1. On the Project menu, click Add Reference.
  2. On the COM tab, click Microsoft Outlook 11.0 Object Library, and then click Select.
  3. Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the library that you selected, click Yes.

And in code you'll have to add this:

Imports Outlook = Microsoft.Office.Interop.Outlook

More info found here: Handy Tasks Using Microsoft Office Outlook 2003 and Visual Basic .NET

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

半城柳色半声笛 2024-11-25 19:34:11
Imports Microsoft.Office.Interop

'On the Project menu, click Add Reference.
'On the COM tab, Double click ->  Microsoft Outlook xx.0 Object Library

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 = CType(oApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
        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 = "[email protected]"

        ' 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 Integer = 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
Imports Microsoft.Office.Interop

'On the Project menu, click Add Reference.
'On the COM tab, Double click ->  Microsoft Outlook xx.0 Object Library

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 = CType(oApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
        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 = "[email protected]"

        ' 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 Integer = 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文