Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Node.js Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Node.js) Fetch Full Email Given Email Header

When email headers are fetched using UIDs (not sequence numbers), then the resultant email object (containing only the header) will include auto-generated ckx-imap-* header fields to record information about the uid, attachments, etc. The IMAP UID of the email will be available in the "ckx-imap-uid" header. There will also be a "ckx-imap-isUid" header field having the value "YES" or "NO". If the email header was downloaded by UID, then "ckx-imap-isUID" will contain the value "YES" and the value of the "ckx-imap-uid" header field is the IMAP UID. If the "ckx-imap-isUID" header has a value of "NO", then the "ckx-imap-uid" header field represents the sequence number. (Sequence numbers of emails on the server can change over time, depending on whether emails are deleted. UIDs must be used to ensure that the correct full email is downloaded.)

The Chilkat Email object provides a GetImapUid method to return the UID from the ckx-imap-uid header. This can then be used to download the full email using the FetchSingle method. Assuming the UID is known, download a single email by UID from an IMAP mail server.

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node10_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node10_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node10_linux32');
    } else {
        var chilkat = require('chilkat_node10_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node10_macosx');
}

function chilkatExample() {

    var imap = new chilkat.Imap();

    var success;

    //  Anything unlocks the component and begins a fully-functional 30-day trial.
    success = imap.UnlockComponent("Anything for 30-day trial");
    if (success !== true) {
        console.log(imap.LastErrorText);
        return;
    }

    //  Connect to an IMAP server.
    //  Use TLS
    imap.Ssl = true;
    imap.Port = 993;
    success = imap.Connect("imap.someMailServer.com");
    if (success !== true) {
        console.log(imap.LastErrorText);
        return;
    }

    //  Login
    success = imap.Login("***","***");
    if (success !== true) {
        console.log(imap.LastErrorText);
        return;
    }

    //  Select an IMAP mailbox
    success = imap.SelectMailbox("Inbox");
    if (success !== true) {
        console.log(imap.LastErrorText);
        return;
    }

    // emailHeader: Email
    var emailHeader;
    // emailFull: Email
    var emailFull;

    var uid = 2014;
    var isUid = true;

    //  Fetch only the email header
    emailHeader = imap.FetchSingleHeader(uid,isUid);
    if (!(emailHeader == null )) {

        //  Now fetch the full email
        var uidFromCkxHeader = emailHeader.GetImapUid();
        if (uidFromCkxHeader < 0) {
            //  Failed.

            console.log("No ckx-imap-uid header was found.");
            return;
        }

        emailFull = imap.FetchSingle(uidFromCkxHeader,true);
        if (!(emailFull == null )) {

            //  OK, we have the full email, do whatever we want...

        }

    }

    //  Disconnect from the IMAP server.
    success = imap.Disconnect();

}

chilkatExample();

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.