我使用以下代码在SMTP服务器的分拣目录中放置和发送电子邮件。目前整个文件是内联组成的。我希望能够使用模板文件和文件持有者来创建文件,因为我们将使用HTML并希望有时更改电子邮件。
Dim objFSO 'As FileSystemObject
Dim objTextFile 'As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("\\CampSaverS2\inetpub\mailroot\Pickup\"&rs.fields("OrderNumber")&".txt")
'rs.fields("OrderNumber") calls the order number, rs.fields("Name") calls customer name, app.S.get("Tracking_Number") calls tracking, rs.fields("email") for email
objTextFile.Write("to:"&rs.fields("email")& vbCrLf &_
"from:adsitest@campsaver.com"& vbCrLf &_
"subject:Tracking Test"& vbCrLf &_
"MIME-Version: 1.0"& vbCrLf &_
"Content-Type: text/html; charset=”iso-8859-1"& vbCrLf &_
"Content-Transfer-Encoding: quoted-printable"& vbCrLf &_
'HTML will go here
"Test email <br> Tracking info for order " & rs.fields("OrderNumber") & " is " & app.S.get("Tracking_Number") & vbCrLf & "Sent From ADSI.")
objTextFile.Close
答案 0 :(得分:0)
您应该能够根据自己的需要进行调整:
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTemplateTS
Const ForReading = 1
Set objTemplateTS = objFSO.OpenTextFile("C:\MyTemplate.txt", ForReading, False)
Dim strAllTemplateText
strAllTemplateText = objTemplateTS.ReadAll()
objTemplateTS.Close()
strAllTemplateText = Replace(strAllTemplateText, "<Placeholder_One>", "My First New Value")
strAllTemplateText = Replace(strAllTemplateText, "<Placeholder_Two>", "My Second New Value")
Dim objOutputTS
Const ForWriting = 2
Set objOutputTS = objFSO.OpenTextFile("C:\Output.txt", ForWriting, True)
objOutputTS.Write(strAllTemplateText)
objOutputTS.Close()