VBScript
VBScript
Change the Filename of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.SetAttachmentFilename method, which changes the filename of the attachment at a given zero-based index. This example adds an attachment and renames it, printing the filename before and after.
Background: The attachment filename is what a recipient sees and what most clients suggest when saving the file. Renaming it is handy when the original name is unclear, unsafe, or generic — for example giving a machine-generated
tmp12345 a meaningful name like invoice.pdf before sending.Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Demonstrates the SetAttachmentFilename method, which changes the filename of the
' attachment at the given zero-based index.
set email = CreateObject("Chilkat.Email")
email.Subject = "Set attachment filename"
success = email.AddStringAttachment("oldname.txt","Some notes.")
outFile.WriteLine("Filename before: " & email.GetAttachmentFilename(0))
' Change the filename of the first attachment (index 0).
success = email.SetAttachmentFilename(0,"newname.txt")
If (success = 0) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Filename after: " & email.GetAttachmentFilename(0))
outFile.Close