如何从Outlook获取附件名称? [英] How to get attachments name from outlook?
本文介绍了如何从Outlook获取附件名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Outlook获取附件名称?使用C#.我有电子邮件的正文,发件人的电子邮件地址,如何获取附件名称以及如何获取这些附件?
谢谢..我得到了附件名称.如何获得这些附件.像文本文档,pdf文件,图像一样.等等.请指导我!
How to get attachments name from outlook? using C#. I have got the body of the email, sender email address, How to get the attachment names and how to get those attachments?
Thanks.. i got the attachment names. How to get those attachements. Like a text document, pdf file, Image. etc.. Please guide me!!!
推荐答案
^ ]
C# Code snippet to send an Email with attachment from Outlook, Yahoo, HotMail, AOL and Gmail[^]
<pre>using System.Text;
// ...
private void GetAttachmentsInfo(Outlook.MailItem email)
{
StringBuilder attachmentInfo = new StringBuilder();
Outlook.Attachments mailAttachments = email.Attachments;
if (mailAttachments != null)
{
for (int i = 1; i < = mailAttachments.Count; i++)
{
Outlook.Attachment currentAttachment = mailAttachments.Item(i);
if (currentAttachment != null)
{
attachmentInfo.AppendFormat(
"#{0}\n\rFile name: {1}\n\rDisplay Name: {2}\n\rType: {3}\n\n\r",
i, currentAttachment.FileName, currentAttachment.DisplayName,
currentAttachment.Type);
Marshal.ReleaseComObject(currentAttachment);
}
}
if (attachmentInfo.Length > 0)
System.Windows.Forms.MessageBox.Show(
attachmentInfo.ToString(), "E-mail attachments");
Marshal.ReleaseComObject(mailAttachments);
}
}
从这两者中您都可以排除所需的资源....
from both you can drive out what you need....
private void GetAttachments(Outlook.MailItem mailItem)
{
Outlook.Attachments attachments = mailItem.Attachments;
if (attachments != null && attachments.Count > 0)
{
for (int i = 1; i <= attachments.Count; i++)
{
Outlook.Attachment attachment = attachments[i];
if (attachment.Type == Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue)
{
// here you can get file name as
//string filename = attachment.FileName;
// if you want to save path in d:\Attachments\ then try as
string filename = Path.Combine(@"d:\Attachments\", attachment.FileName);
attachment.SaveAsFile(filename);
}
}
}
}
这篇关于如何从Outlook获取附件名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文