+2 votes

I need to create a new email and copy some attachments of another email. is there any way to do it without downloading all the attachments locally?

by

1 Answer

0 votes

It is possible, but not without downloading the original email (along with attachments).

Neither IMAP nor POP3 protocol allow coping attachments between emails, as attachments are integral part of an email message.

The code to copy the attachments when original email is downloaded is quite simple:

IMail original = ...;

MailBuilder builder = new MailBuilder();
foreach (MimeData attachment in original.Attachments)
{
    builder.AddAttachment(attachment);
}
builder.Subject = "Email with copied attachments";
IMail email = builder.Create();

If you care about inline/non-visual/alternatives use appropriate collections (IMail.Visuals, IMail.NonVisuals, IMail.Alternatives) and appropritae MailBuilder methods (AddVisual, AddAttachment, AddAlternative)

If you are forwarding a message or replying to one, consider using IMail.Forward or IMail.Reply:
https://www.limilabs.com/blog/forward-email
https://www.limilabs.com/blog/reply-to-email

by (288k points)
...