Add DisplayName to MailAttachment

Hi

In EWS it is pissible to add an attachement using both a path and a displayname:
AttachmentCollection.AddFileAttachment Method (Microsoft.Exchange.WebServices.Data) | Microsoft Learn

That way if I had like this file:

C:\myFiles\1acad546-56c7-4a3c-95a3-5cb7ad6e6944.pdf

… then in EWS I can add the attachment like this:

mail.Attachments.AddFileAttachment(“invoice.pdf”, “C:\myFiles\1acad546-56c7-4a3c-95a3-5cb7ad6e6944.pdf”)

… and the end user will see it as “invoice.pdf”.

To do the same with GemBox, I need to move the file to a unique folder (so I dont have duplicate filenames), rename the file and then attach the file.

Is it possible for you to add “DisplayName” to GemBox.Email attachements, so I don’t need to do unnecessary time consuming workarounds?

Thanks :slight_smile:

Hi Morten,

Try this:

MailMessage message = ...

using var stream = File.OpenRead("C:\\myFiles\\1acad546-56c7-4a3c-95a3-5cb7ad6e6944.pdf");
var attachment = new Attachment(stream, "invoice.pdf");

message.Attachments.Add(attachment);

Does this solve your issue?

Regards,
Mario