自动电子邮件错误与VB.net在Office 2013环境 [英] Automatic Email Error with VB.net in Office 2013 Environment

查看:330
本文介绍了自动电子邮件错误与VB.net在Office 2013环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个vb.net脚本从Outlook发送自动电子邮件。它目前在Office 2010 Suite中可用。我将我的环境升级到2013年,现在它不工作。我在做什么并不复杂我想做的只是抓住一个.pdf并附加到一个电子邮件。然后添加收件人并发送电子邮件。崩溃的地方是电子邮件的实际发送。它抛出这个执行

  System.Runtime.InteropServices.COME发生在Microsoft.VisualBasic.dll 
附加信息:操作中止(从HRESULT执行:0x80004004(E_ABORT))

我在想,因为我升级了环境不正确地引用200的X- 200 X- 200 X- 200 X- 200 X- 200 X- 200 X- 200 X- 200 X-以下是我的代码,任何帮助将不胜感激!感谢高级。

 导入Outlook = Microsoft.Office.Interop.Outlook 
模块Module1

Sub main()
sendEmail()
End Sub

Public Sub sendEmail()
Dim ol As Object
Dim mail AS Object
ol = CreateObject(Outlook.Application)
mail = ol.CreateItem(0)
mail.To =email@example.com
mail.Subject =主题行
mail.Body =正文
mail.Attachments.Add(path\to\attachment.pdf)

mail.Send()'崩溃在这一行
mail = Nothing
ol = Nothing
End Sub
结束模块

另外我在Windows 7上运行Office 2013套件。看看App.config我支持的运行时版本是v4.0,而.NetFramework版本是v4.5

解决方案

解决方案是自动化Outlook跨进程,您首先需要确保这些类型的应用程序获得授权,因此请检查Outlook的信任中心中的防病毒状态:



https://msdn.microsoft.com/en-us/library/office/ff864479.aspx



我还会将CreateObject调用包装在Try / Catch块中,以确保不会开始。还要确保您已创建一个Outlook配置文件,并且您的应用程序不是通过任务计划程序进程或Web应用程序运行在非授权安全上下文。


I have a vb.net script that sends automatic emails from Outlook. It currently works in the Office 2010 Suite. I upgraded my environments to 2013 and now it is not working. What I'm doing isn't complicated. All I want to do is grab a .pdf and attache it to an email. Then add the recipients and send the email. The place where it crashes is the actual sending of the email. It throws this execption

System.Runtime.InteropServices.COMEception occurred in Microsoft.VisualBasic.dll
Additional information: Operation aborted (Execption from HRESULT: 0x80004004 (E_ABORT))

I'm thinking because I upgraded environments something isn't referenced correctly. But I can't seem to find a fix. Below is my code, any help would be greatly appreciated! Thanks in advanced.

Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1

   Sub main()
      sendEmail()
   End Sub

   Public Sub sendEmail()
      Dim ol As Object
      Dim mail AS Object
      ol = CreateObject("Outlook.Application")
      mail = ol.CreateItem(0)
      mail.To = "email@example.com"
      mail.Subject = "Subject Line"
      mail.Body = "Body text"
      mail.Attachments.Add("path\to\attachment.pdf")

      mail.Send()                 'crashes on this line
      mail = Nothing
      ol = Nothing
   End Sub
End Module

Also I am running on Windows 7 with the Office 2013 suite. Looking at the App.config my supported Runtime version is v4.0 and the .NetFramework version is v4.5

解决方案

Since your solution is automating Outlook cross-process you first need to ensure that these types of applications are authorized so check your anti-virus state in Outlook's Trust Center:

https://msdn.microsoft.com/en-us/library/office/ff864479.aspx

I would also wrap the CreateObject call in a Try/Catch block to ensure that isn't failing to begin with. Also make sure that you have an Outlook profile created and that your application isn't running under a non-authorized security context like via a Task Scheduler process or in a web application.

这篇关于自动电子邮件错误与VB.net在Office 2013环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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