1
因此,我希望能夠從電子郵件中獲取XML文件附件並將其存儲在數據庫中供以後使用。從電子郵件附件獲取XML文件到變量
我可以檢索電子郵件並將SenderEmailAdress,sentOn和正文存儲在數據庫中。現在我想將XML文件附件添加到數據庫中,以便稍後使用它。
如何從電子郵件和變量中獲取附件文件(或內容),以便將其添加到數據庫中?
下面是附件我現在有(所以以後我得到的郵件項目)代碼:
//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;
}
}
}
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.attachment.saveasfile(v=office.14).aspx – montewhizdoh