将单个电子邮件发送给预定义的一组人员,其中包含文件夹中的所有文件

发布于 2024-11-01 19:52:42 字数 1148 浏览 3 评论 0原文

我有一堆在文件夹“C:\Email”中更新的文件。这些是每周创建的 PDF 文件。文件数量可能在 50 到 500 之间,甚至更多。文件名是随机的。

我需要将这些文件分别发送到三个地址,例如 [email protected] ,[电子邮件受保护][电子邮件]受保护]。我无法一次性发送所有文件,它们需要单独发送。主题将是文件的名称,正文将保持不变 - “请查找附件。谢谢并致以问候,ABC”。

我一直在使用几个 Excel 工作表的组合,其中我使用命令行语法(即“C:\Program Files\Microsoft Office\Office12\Outlook.txt”)连接所有必需的参数,以得出批处理文件的文件名。 exe /c ipm.note /m "[电子邮件受保护],[电子邮件]受保护][电子邮件受保护]&subject=<>&body=请查找附件。谢谢和问候,ABC”

这是我今天想到的最简单的事情,但它很麻烦,因为它会打开与文件一样多的 Outlook 新消息窗口,这可能会让人厌烦。其次,这不允许我发送消息 。

希望有人能够提出一个 VBS / Windows 脚本 / VBA 代码来自动化执行相同的操作

I have a bunch of files that get updated in the folder "C:\Email". These are PDF files that are created on a weekly basis. This could number from anywhere between 50 to 500 or more files. The file names are random.

I need to send out these files individually to three addresses say [email protected],[email protected] and [email protected]. I cannot send all the files in one go, they need to go individually. The subject will be the name of the file and the body will remain the same - "Please find attached file. Thanks and Regards, ABC".

I have been using a combination of a few excel sheets where i concatanate all the required parameters to to come up with the file names for a batch file using the command line syntax i.e. "C:\Program Files\Microsoft Office\Office12\Outlook.exe /c ipm.note /m "[email protected],[email protected],[email protected]&subject=<>&body=Please find attached file. Thanks and Regards, ABC"

this is the simplest thing I have come up with today but it is cumbersome as it opens up as many outlook new message windows as there are files, which can get tiresome. Secondly this does not let me send the message automatically.

Hope some one can come up with a VBS / Windows script / VBA code to automate the same.

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

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

发布评论

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

评论(3

平安喜乐 2024-11-08 19:52:43

您可以尝试使用 CDO.Message 对象从 VBScript 发送电子邮件。以下是取自 http://www.paulsadowski.com/wsh/cdo.htm

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Example CDO Message" 
objMessage.From = "[email protected]" 
objMessage.To = "[email protected]" 
objMessage.TextBody = "This is some sample message text." 
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

您可以将其放入循环结构中以发送文件夹中的每个文件

You can try sending email from VBScript using a CDO.Message object. Here is an example taken from http://www.paulsadowski.com/wsh/cdo.htm

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Example CDO Message" 
objMessage.From = "[email protected]" 
objMessage.To = "[email protected]" 
objMessage.TextBody = "This is some sample message text." 
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

You would place this into a loop structure to send each file in the folder

羅雙樹 2024-11-08 19:52:43

将代码替换

Do While Len(fileName) > 0     
Call CreateEmail(SOURCE_FOLDER & fileName)      
Dir (SOURCE_FOLDER)   
Loop  

Do While Len(fileName) > 0     
Call CreateEmail(SOURCE_FOLDER & fileName)      
filename = Dir   
Loop 

Replace the code

Do While Len(fileName) > 0     
Call CreateEmail(SOURCE_FOLDER & fileName)      
Dir (SOURCE_FOLDER)   
Loop  

with

Do While Len(fileName) > 0     
Call CreateEmail(SOURCE_FOLDER & fileName)      
filename = Dir   
Loop 
岁月静好 2024-11-08 19:52:42

使用 Dir Loop 抓取每个 PDF 文件并创建新电子邮件。像这样:

Const SOURCE_FOLDER As String = "C:\Email\"
Const RECIP_A As String = "[email protected]"
Const RECIP_B As String = "[email protected]"
Const RECIP_C As String = "[email protected]"
Const EMAIL_BODY As String = "Please find attached file. Thanks and Regards, ABC"

Sub SendPDFs()

  On Error GoTo ErrorHandler

  Dim fileName As String

  fileName = Dir(SOURCE_FOLDER)

  Do While Len(fileName) > 0
    Call CreateEmail(SOURCE_FOLDER & fileName)

    Dir (SOURCE_FOLDER)
  Loop

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.description
  Resume ProgramExit
End Sub

Function CreateEmail(fileName As String)

Dim olApp As Outlook.Application
Dim msg As Outlook.MailItem

  ' create email
  Set olApp = Outlook.Application
  Set msg = olApp.createitem(olMailItem)

  ' set properties
  With msg
    .Body = EMAIL_BODY
    .Recipients.Add (RECIP_A)
    .Recipients.Add (RECIP_B)
    .Recipients.Add (RECIP_C)
    .Attachments.Add fileName
    .Send
  End With

End Function

这会将电子邮件文件夹中的每个文件发送给每个收件人,但不会为每个 PDF 发送三封单独的电子邮件。如果您特别需要,可以更改代码。

Use a Dir Loop to grab each PDF file and create a new email. Something like this:

Const SOURCE_FOLDER As String = "C:\Email\"
Const RECIP_A As String = "[email protected]"
Const RECIP_B As String = "[email protected]"
Const RECIP_C As String = "[email protected]"
Const EMAIL_BODY As String = "Please find attached file. Thanks and Regards, ABC"

Sub SendPDFs()

  On Error GoTo ErrorHandler

  Dim fileName As String

  fileName = Dir(SOURCE_FOLDER)

  Do While Len(fileName) > 0
    Call CreateEmail(SOURCE_FOLDER & fileName)

    Dir (SOURCE_FOLDER)
  Loop

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.description
  Resume ProgramExit
End Sub

Function CreateEmail(fileName As String)

Dim olApp As Outlook.Application
Dim msg As Outlook.MailItem

  ' create email
  Set olApp = Outlook.Application
  Set msg = olApp.createitem(olMailItem)

  ' set properties
  With msg
    .Body = EMAIL_BODY
    .Recipients.Add (RECIP_A)
    .Recipients.Add (RECIP_B)
    .Recipients.Add (RECIP_C)
    .Attachments.Add fileName
    .Send
  End With

End Function

This will send each file in the Email folder to each recipient, but it doesn't send three separate emails for each PDF. If you need that specifically, the code can be changed.

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