Developer Network
Developer Network
Developer
:CreateViewProfileText:
Sign in
Subscriber portal
Get tools
Downloads
Visual Studio
SDKs
Trial software
Free downloads
Office resources
Programs
Subscriptions
Overview
Administrators
Students
Microsoft Imagine
Microsoft Student Partners
ISV
Startups
Events
Community
Magazine
Forums
Blogs
Channel 9
Documentation
APIs and reference
Dev centers
Samples
Retired content
We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second.
Ask a question
Quick access
Forums home
Browse forums users
FAQ
Search related threads
Remove From My Forums
Asked by:
How To save attachments? Outlook! C#
Archived Forums V
>
Visual C# Express Edition
Question
0
Sign in to vote
Look my code... im save a menssages... but i dont save attachments =/
_____________________________________________
static void Main(string[] args)
{
try
{
//Criando a aplicação
Outlook.Application oApp = new Outlook.Application();
//Pegando o namespace MAPI
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
//Logando usando o profile default
oNS.Logon(Missing.Value, Missing.Value, false, true);
//Pegando o Folder
Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
//Pegando os itens do inbox
Outlook.Items oItems = oInbox.Items;
// Pegado a primeira menssagem
Outlook.MailItem oMsg = (Outlook.MailItem)oItems.GetLast();
//Retirando os Acentos...
string subject = oMsg.Subject.ToString().Replace(':', '_')
.Replace('*', '_')
.Replace('/', '_')
.Replace('?', '_')
.Replace('"', '_')
.Replace('<', '_')
.Replace('>', '_')
.Replace('|', '_');
//Propriedade
Directory.CreateDirectory("C:\\teste\\");
StreamWriter oFile = new StreamWriter("C:\\teste\\" + subject + ".txt");
oFile.WriteLine("Assunto: "+oMsg.Subject);
oFile.WriteLine("Enviado por: "+oMsg.SenderName);
oFile.WriteLine("Data Recebida: "+oMsg.ReceivedTime);
oFile.WriteLine(oMsg.Body);
oFile.Close();
//Checando c tem atacchments
int AttachCnt = oMsg.Attachments.Count;
Console.WriteLine("Attachments: " + AttachCnt.ToString());
if (AttachCnt > 0)
{
for (int i = 1; i <= AttachCnt; i++)
Console.WriteLine(i.ToString() + "-" + oMsg.Attachments
.DisplayName);
}
//Deslogando.
oNS.Logoff();
//Release dos Objetos.
oMsg = null;
oItems = null;
oInbox = null;
oNS = null;
oApp = null;
}
//Caso de Algum erro
catch (Exception e)
{
Console.WriteLine("{0} Exception caught: ", e);
}
}
___________________________________________
Please Help me to save attachments!
Thank's
Tuesday, October 17, 2006 7:32 PM