Microsoft Visual Studio 中的引用不起作用
目前,我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在“解决方案资源管理器”中,右键单击您的项目并选择“添加引用”,然后向下滚动,直到看到 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.
添加对“Microsoft Outlook 11.0 对象库”的引用:
在代码中,您必须添加以下内容:
此处找到更多信息:使用 Microsoft Office Outlook 2003 和 Visual Basic .NET 的便捷任务
但如果您使用 .NET,为什么不使用 System.Net.Mail?
Add a reference to the "Microsoft Outlook 11.0 Object Library":
And in code you'll have to add this:
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?