【问题标题】:VB script for send mail adding multiple variable recipients用于发送邮件添加多个可变收件人的 VB 脚本
【发布时间】:2015-10-14 10:57:11
【问题描述】:

我对编写 VB 脚本比较陌生。本质上,我需要一个正常工作的 VB 脚本来向多个收件人发送一封电子邮件,这些收件人的每封电子邮件各不相同。我需要它具有主题行、电子邮件正文、附件和在 TO、CC 和 BCC 字段中添加多个收件人的灵活性,而无需为 TO 字段中的每个电子邮件地址添加单独的 Add.Recipient 行。有没有人有任何建议或知道任何资源来查找此信息?

我看了看自己,对此有些茫然。我在一个单独的.txt 文件中设置了参数。这些会不断变化。我正在尝试尽快但有效地做到这一点。

我对 Add.CC 命令也不太满意,所以我把它拿出来作为这个例子……下面是我目前写的,

Set args = WScript.Arguments
arg1 = args.Item(0)  
arg2 = args.Item(1)
arg3 = args.Item(2)
ToAddress = ""&arg1&""
CCAddress = ""&arg2&""
MessageSubject = "Your Order"
MessageBody = "Please find your Order Attached" 
MessageAttachment = ""&arg3&""  
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send

我的论点写成:

cscript //nologo test1.vbs email1@email.com email2@email.com y:\folder\test.txt 

【问题讨论】:

  • 伙计,我希望投反对票的人能够发表评论以帮助用户改进问题。无论如何,这个问题真的很广泛。您提供了您要完成的工作的良好背景并提供了代码,但未能描述特定问题。你特别坚持什么?有各种各样的关于这类事情的教程(这里是其中之一:youtu.be/Tvbn1HPUSMY)你检查了吗?准确了解您遇到的问题并提出问题;你会得到更好的结果。祝你好运!
  • 问题很清楚如何处理未知长度的列表

标签: email vbscript arguments cc


【解决方案1】:
'Get email addresses, the -2 ignores the attachment
For x = 0 to WScript.Arguments.Count - 2 
    Msgbox Wscript.Arguments(x) & "Count " & x
Next
Msgbox Wscript.Arguments(wscript.arguments.count - 1) & " Attachment"

在编程中,我们主要使用程序步骤,就像您一样。然而,我们经常需要做循环。因为我们只想要最后一个,然后是最后一个,所以我使用了For x = 循环。 For Each 循环通常是更好更简洁的代码。

这会打印出所有参数

For each Ag in WScript.Arguments 
    Msgbox Ag 
Next

【讨论】:

    猜你喜欢
    • 2014-05-25
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 2020-09-15
    • 2014-02-06
    • 2017-04-12
    相关资源
    最近更新 更多