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