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

SQL Server 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
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)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
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

 

 

 

(SQL Server) Email Received Header Fields

Received emails will contain one or more "Received" header fields at the beginning of the email header. Each SMTP server (along the delivery path) adds a Received header to the top of the incoming message. The delivery route can be ascertained by the sequence of Received headers. There is a good summary of the Received header here.

The following explanation is taken from the reference URL above:

In theory, the value of a Received field is tokenizable. It contains

    1) optionally, a "from" atom followed by an encoded domain name;
    2) optionally, a "by" atom followed by an encoded domain name;
    3) optionally, a "via" atom followed by another atom;
    4) zero or more of the following: a "with" atom followed by another atom;
    5) optionally, an "id" atom followed by either (1) an atom or (2) a < token, an encoded address, and a > token;
    6) optionally, a "for" atom followed by an encoded address;
    7) a semicolon; and
    8) a timestamp. 

In practice, SMTP servers put all sorts of badly formatted information into Received lines. It is probably best for readers to treat everything before the final semicolon as unstructured text, purely for human consumption.

This example demonstrates iterating over each of the Recevied headers and getting the content of each.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @email int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Email', @email OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Load a .eml file into the email object.
    DECLARE @success int
    EXEC sp_OAMethod @email, 'LoadEml', @success OUT, '/home/users/chilkat/eml/myEml.eml'

    DECLARE @i int

    DECLARE @numHeaders int
    EXEC sp_OAGetProperty @email, 'NumHeaderFields', @numHeaders OUT
    DECLARE @strName int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.CkString', @strName OUT

    SELECT @i = 0
    WHILE @i <= STR(@numHeaders) - 1
      BEGIN

        DECLARE @caseSensitive int
        SELECT @caseSensitive = 0
        EXEC sp_OAMethod @email, 'GetHeaderFieldName', @sTmp0 OUT, STR(@i)
        EXEC sp_OASetProperty @strName, 'Str', @sTmp0
        EXEC sp_OAMethod @strName, 'StrComp', @iTmp0 OUT, 'Received', STR(@caseSensitive)
        IF @iTmp0 = 0
          BEGIN

            EXEC sp_OAMethod @email, 'GetHeaderFieldValue', @sTmp0 OUT, STR(@i)
            PRINT 'Received: ' + @sTmp0
          END

        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @strName


END
GO

 

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