Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW email;

    success = FALSE;

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

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"Set attachment filename");

    CkEmailW_AddStringAttachment(email,L"oldname.txt",L"Some notes.");
    wprintf(L"Filename before: %s\n",CkEmailW_getAttachmentFilename(email,0));

    //  Change the filename of the first attachment (index 0).
    success = CkEmailW_SetAttachmentFilename(email,0,L"newname.txt");
    if (success == FALSE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return true;
    }

    wprintf(L"Filename after: %s\n",CkEmailW_getAttachmentFilename(email,0));


    CkEmailW_Dispose(email);

    }