How do you save an emails attachments ? (Just Learning)
Thanks
Terence
Hi Terence,
Try this:
// Retrieve or load an email.
MailMessage message = ...
// Specify your output folder for email attachments.
string folder = @"C:\MyAttachment\";
// Iterate through Attachments collection.
foreach (Attachment attachment in message.Attachments)
{
string file = Path.Combine(folder, attachment.FileName ?? Path.GetRandomFileName());
// Save attachment to the path.
File.WriteAllBytes(file, attachment.Data.ToArray());
}
Does this solve your issue?
Regards,
Mario