1

So, I want to be able to get an XML file attachment from an email and store it in the database for later use.

I can retrieve the emails and store the SenderEmailAdress, sentOn and the body in the database. Now I want to add the XML file attachment to the database too, so I can use it later.

How can I get the attachment file (or the content) from the email and to a variable so I can add it to the DB?

Here's the code for the attachment I have now (so after I get the Mail Item):

//Check for attachments.
int AttachCnt = oMsg.Attachments.Count;

// Check if there are any attachments
if (AttachCnt > 0)
{
    for (int i = 1; i <= AttachCnt; i++)
    {
        System.Diagnostics.Debug.WriteLine(i.ToString() + " - FileName: " + oMsg.Attachments[i].FileName);
        String ext = Path.GetExtension(oMsg.Attachments[i].FileName);
        // check if the file extention is .xml
        if (ext == ".xml")
        {
            // Get the file ready to store in the DB. This is what I want to know!
            return;
        }                            
    }                            
}

1 Answer 1

1

Save the attachment as a file (Attachment.SaveAsFile), then read the file data into a variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.