Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Save All Email Attachments to a Directory Example source code to save all email attachments to a directory. // The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Save all attachments to disk.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Download email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i<n; i++)
{
CkEmail *email = bundle->GetEmail(i);
int numAttach = email->get_NumAttachments();
printf("Number of attachments = %d\n",numAttach);
// Save all the attachments to a directory
email->SaveAllAttachments("c:/attachments");
// Now display the actual filenames of the attachments saved to disk
int j;
for (j=0; j<numAttach; j++)
{
// The filename returned by GetAttachmentFilename will not contain
// the directory path. When Chilkat saves attachments, if a file
// of the same name already exists, Chilkat will modify the attachment
// filename to make it unique so nothing is overwritten. After saving
// attachments, the GetAttachmentFilename method returns the name of
// the file saved.
email->GetAttachmentFilename(j,str);
printf(" %d) saved to filename: %s\n",j,str.getString());
}
delete email;
}
delete bundle;
return;
}
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.