Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Download MIME Source of Emails in IMAP MailboxDemonstrates how to download the MIME source for emails on an IMAP server. There are several Chilkat IMAP methods for downloading email into a MIME string: FetchSingleAsMime, FetchSequenceAsMime, and FetchBundleAsMime. This example demonstrates FetchSequenceAsMime.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int DECLARE @sTmp0 nvarchar(4000) DECLARE @imap int EXEC @hr = sp_OACreate 'Chilkat.Imap', @imap OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Anything unlocks the component and begins a fully-functional 30-day trial. EXEC sp_OAMethod @imap, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Connect to an IMAP server. EXEC sp_OAMethod @imap, 'Connect', @success OUT, 'mail.chilkatsoft.com' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Login EXEC sp_OAMethod @imap, 'Login', @success OUT, 'myLogin', 'myPassword' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Select an IMAP mailbox EXEC sp_OAMethod @imap, 'SelectMailbox', @success OUT, 'Inbox' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- The NumMessages property contains the number of messages in the selected mailbox. DECLARE @numToFetch int EXEC sp_OAGetProperty @imap, 'NumMessages', @numToFetch OUT -- Download all the email in the Inbox. DECLARE @sa int EXEC sp_OAMethod @imap, 'FetchSequenceAsMime', @sa OUT, 1, @numToFetch IF @sa Is NULL BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Loop over the MIME strings contained within sa: DECLARE @i int EXEC sp_OAGetProperty @sa, 'Count', @iTmp0 OUT SELECT @i = 0 WHILE @i <= @iTmp0 - 1 BEGIN DECLARE @strMime nvarchar(4000) EXEC sp_OAMethod @sa, 'GetString', @strMime OUT, @i -- Now you have the MIME source of this email... SELECT @i = @i + 1 END -- Disconnect from the IMAP server. EXEC sp_OAMethod @imap, 'Disconnect', NULL END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.