读出 txt 并将最后一行发送到电子邮件地址 - vbscript
你好,
我回来了哈哈:-)所以我有下一个问题,我希望有人能帮助我...... 我知道我有很多问题,但我会尝试学习 vbscript :-)
情况: 该脚本读出(每 5 分钟)txt 的最后一行并将其发送到我的电子邮件地址。
问题: 我会花 5 分钟检查 txt,但目前每 5 分钟就会收到一封邮件。当 txt 中有新内容时,我会尝试仅收到新邮件。
Option Explicit
Dim fso, WshShell, Text, Last, objEmail
Const folder = "C:\test.txt"
Set fso=CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
Text = Split(fso.OpenTextFile(Datei, 1).ReadAll, vbCrLF)
Letzte = Text(UBound(Text))
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "[email protected]"
objEmail.To = "[email protected]"
objEmail.Subject = "Control"
objEmail.Textbody = Last
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtpip"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
WScript.Sleep 300000
Loop
有人可以帮助我吗?
抱歉我的英语不好......
Hallo,
I'm back haha :-) so i have the next question and i hope someone can help me...
I know i have a lot of questions but i will try to learn vbscript :-)
Situation:
This script read out (every 5 min) the last line of a txt and send it to my eMail Address.
Problem:
I'll check the txt all 5 min, but at the moment every 5 min there comes a mail. I'll try to get only a new mail, when there is something new in the txt.
Option Explicit
Dim fso, WshShell, Text, Last, objEmail
Const folder = "C:\test.txt"
Set fso=CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
Text = Split(fso.OpenTextFile(Datei, 1).ReadAll, vbCrLF)
Letzte = Text(UBound(Text))
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "[email protected]"
objEmail.To = "[email protected]"
objEmail.Subject = "Control"
objEmail.Textbody = Last
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtpip"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
WScript.Sleep 300000
Loop
Can someone help me?
Sry for my bad english...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
try this
您只收到一封邮件的原因是由于 UBound,它只能获取数组的最后一个元素。
要为每一行发送邮件,您必须在发送邮件后记住上限,然后循环遍历各行
The reason that you only get one mail is because of the UBound, which only gets you the last element of the array.
To send a mail for each line, you will have to remember the upper bound after sending the mails and then loop over the lines