Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email

li_Success = 0

//  Demonstrates the SetAttachmentFilename method, which changes the filename of the
//  attachment at the given zero-based index.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Set attachment filename"

loo_Email.AddStringAttachment("oldname.txt","Some notes.")
Write-Debug "Filename before: " + loo_Email.GetAttachmentFilename(0)

//  Change the filename of the first attachment (index 0).
li_Success = loo_Email.SetAttachmentFilename(0,"newname.txt")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

Write-Debug "Filename after: " + loo_Email.GetAttachmentFilename(0)


destroy loo_Email