我已经在ASP.NET中使用VB创建了一个应用程序。我写了下面的代码。尝试使用ASP.NET打开Outlook
它给本地主机上的错误,但当我从我的应用程序运行它,它工作正常。
我检查了DCOMCNFG - > Outlook/Office条目不存在。
请指教我如何打开Outlook与我的应用程序在本地主机/服务器附件?
ByVal recipients As List(Of String),
ByVal smtpAddress As String,
ByVal attachments As List(Of String))
' Create a new MailItem and set the To, Subject, and Body properties.
'Dim application As New Outlook.Application
Dim application As New Outlook.Application()
Threading.Thread.Sleep(2000)
Dim newMail As Outlook.MailItem = DirectCast(application.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
' Set up all the recipients.
For Each recipient In recipients
newMail.Recipients.Add(recipient)
Next
If newMail.Recipients.ResolveAll() Then
newMail.Subject = subject
newMail.Body = body
For Each attachment As String In attachments
newMail.Attachments.Add(attachment, Outlook.OlAttachmentType.olByValue)
Next
End If
newMail.Display(True)
如果您希望在客户端计算机上调用Outlook,则无法从服务器上的代码执行此操作。试想一下,如果任何网站可以在查看它的计算机上运行任何程序。如果您希望在Web服务器上调用Outlook,那么您的运气再好不过了,因为Office应用程序无法可靠地以这种方式使用:它们被设计为具有交互式UI,而Web服务器没有这种交互式UI。但是,您可以从服务器发送电子邮件; [System.Net.Mail](http://www.systemnetmail.com/default.aspx)网站涵盖了该主题。 –