gpt4 book ai didi

vbscript - 发送正文作为文本文件内容的 outlook 电子邮件

转载 作者:行者123 更新时间:2023-12-04 02:52:11 24 4
gpt4 key购买 nike

我想使用 VBScript 发送 outlook 电子邮件。电子邮件的正文应包含文本文件的内容,例如 sha.txt。下面是我正在使用的代码,但它给了我这个错误:

Run Time error '287': Application-defined or Object defined error

Sub email1()   
Dim outobj, mailobj
Dim strFileText
Dim objFileToRead

Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\sonu\Desktop\auto\sha.txt", 1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
Set objFileToRead = Nothing
With mailobj
.To = "user@user.com"
.Subject = "Testmail"
.Body = strFileText
.Send
End With

'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
End Sub

最佳答案

    'I didn't look into the particular issue with your file reading.
'Below my example, just tested it works.
'Good luck mate :)

Sub CatchMe()

Dim outobj, mailobj
Dim strFileText
Dim objFileToRead

Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
strFileText = GetText("C:\Share\1.txt")

With mailobj
.To = "user@user.com"
.Subject = "Testmail"
.Body = strFileText
.Display
End With

'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing

End Sub

Function GetText(sFile As String) As String
Dim nSourceFile As Integer, sText As String
nSourceFile = FreeFile
'Write the entire file to sText
Open sFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close
GetText = sText
End Function

关于vbscript - 发送正文作为文本文件内容的 outlook 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com