简体   繁体   English

如何从VBA中的Outlook发件箱发送所有电子邮件

[英]How to Send All Emails From Outlook Outbox in VBA

I'm using Excel VBA to stage emails in Outlook and it is working well. 我正在使用Excel VBA在Outlook中暂存电子邮件,并且运行良好。

Dim template As Outlook.MailItem, tomerge As Outlook.MailItem
' Create E-mail
tomerge.Close olSave

The e-mails can then be manually moved to the Drafts folder and sent using this Sub . 然后可以将电子邮件手动移动到“草稿”文件夹并使用此Sub发送

'Loop through items in Drafts folder
objDrafts.Item(i).Send

However, many users have a bunch of extra drafts in their Drafts folder that they don't want sent. 但是,许多用户在“草稿”文件夹中有一堆不想发送的多余草稿。

If I replace "olFolderDrafts" with "olFolderOutbox" and try to send from their Outbox. 如果我将“ olFolderDrafts”替换为“ olFolderOutbox”,并尝试从其发件箱发送邮件。 The first message sends and then I get a "Run-time error" "Outlook has already begun transmitting this message". 发送第一个消息,然后出现“运行时错误”“ Outlook已经开始发送此消息”。

Is there some way to send all from the Outbox or even better is there someway to stage and send from a newly created folder? 是否可以通过某种方式从发件箱发送所有邮件, 或者更好的是可以通过某种方式登台并从新创建的文件夹发送邮件?

You need to create a folder for your unsent items and process them separately. 您需要为未发送的项目创建一个文件夹,并分别进行处理。 As a rule the Outbox folder contains already submitted items. 通常, Outbox文件夹包含已提交的项目。 So, that's not a right place for your items. 因此,这不是您放置物品的合适位置。

The Outlook Object Model provides the Add function of the Folders class. Outlook对象模型提供Folders类的Add函数。 You can get an instance of the Folders class using the Folders property of the Folder class in Outlook. 您可以使用Outlook中Folder类的Folders属性获取Folders类的实例。 You can read more about that in the How To: Create a new folder in Outlook article. 您可以在如何:在Outlook中创建新文件夹文章中了解有关此内容的更多信息。

This answer was inspired by Nagarajan's comment above, but there are quite a few changes necessary from the answer in Send/Receive in Outlook Via Code . 这个答案的灵感来自Nagarajan的上述评论,但是与Outlook Via Code中的Send / Receive中的答案相比,还需要进行很多更改。 The main problem is using olSave doesn't put the messages in a "ready to send" state in Outlook so starting a sync using syc.Start from the answer above does nothing. 主要问题是使用olSave不会在Outlook中将邮件置于“准备发送”状态,因此使用syc.Start 。开始同步从上面的答案起什么都没有做。

Instead, we found the following process to be straight forward: 相反,我们发现以下过程很简单:

  1. Put Outlook in offline mode using "Send/Recieve" -> "Work Offline" 使用“发送/接收”->“脱机工作”将Outlook置于脱机模式
  2. Use Excel VBA to stage the e-mails and instead of saving just .Send each email. 使用Excel VBA .Send电子邮件,而不是仅.Send.Send每封电子邮件。 As Outlook is offline they will be staged and ready to be sent but not actually sent. 由于Outlook处于脱机状态,因此它们将被暂存并准备发送,但实际上并未发送。
  3. The e-mails should now be staged in Outlook's Outbox folder and can be reviewed just be sure to press the "send" button after reviewing/editing messages otherwise the e-mail you modified will be removed from the queue. 现在应该将电子邮件放在Outlook的“发件箱”文件夹中,并且可以进行审阅,只需确保在审阅/编辑邮件后按“发送”按钮,否则您修改的电子邮件将从队列中删除。
  4. When the messages are ready to be sent put Outlook back in online mode and they will be sent automatically. 当邮件准备好发送时,将Outlook置于联机模式,它们将自动发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM