Archived Forum Post

Index of archived forum posts

Question:

How to Save an Email Attachment with a Custom Name?

Dec 13 '12 at 14:27

And I need save Attachment with my custon name! Have any way to do this, for sample:

std::string my_dir = "/temp/mydir";
std::string my_new_file_name = "my_new_artifical_name.xml";
if (email->SaveAttachedFile(j, (my_dir + "/" + my_new_file_name).c_str()) != true) 

Answer

You would call the email->SetAttachmentFilename method to set the Nth attachment's filename. For example:

email->SetAttachmentFilename(j,"my_new_artifical_name.xml");

Then call SaveAttachedFile as before. The 2nd argument to SaveAttachedFile is the target directory (without the filename).