Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Node.js Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Node.js) Create MDN (Message Disposition Notification) Email

Demonstrates how to create a MDN (Message Disposition Notification) Email having the format as defined in RFC 3798.

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') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}

function chilkatExample() {

    var email = new chilkat.Email();

    var success;

    // An MDN can be used to notify the
    // sender of a message of any of several conditions that may occur after
    // successful delivery, such as display of the message contents,
    // printing of the message, deletion (without display) of the message,
    // or the recipient's refusal to provide MDNs.
    // (for more information, see RFC 3798)

    // IMPORTANT:
    // Note: Please be careful in sending automated MDN's.
    // It is important to be aware of an issue called "backscatter".
    // See the Wikipedia article here:  http://en.wikipedia.org/wiki/Backscatter_%28e-mail%29

    // The CreateMdn method is called to create a new
    // MDN email based upon the email object calling CreateMdn.
    // The email object instance used to call CreateMdn would
    // typically be an email received from a POP3 or IMAP server.
    // In this case, to simplify the example, we'll load the email
    // from a .eml file.

    // This example will be creating a MDN for "someEmail.eml"
    success = email.LoadEml("someEmail.eml");
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

    // The MDN created by CreateMdn will contain a 
    // "message/disposition-notification" MIME sub-part that will
    // be composed of a number of name-value pairs.
    // See RFC 3798  ( http://tools.ietf.org/html/rfc3798 )
    // The name-value content for this part is passed
    // as XML to CreateMdn. This part of the example
    // prepares the XML:
    var xml = new chilkat.Xml();

    // For this example, we're just adding a few name-value pairs.
    // These should not be considered to be correct, required or
    // even sensible -- they are simply for the example.  
    xml.Tag = "DispositionFields";
    xml.NewChild2("Disposition","manual-action/MDN-sent-manually; displayed");
    xml.NewChild2("Original-Message-ID",email.GetHeaderField("Message-ID"));
    xml.NewChild2("Final-Recipient",email.GetToAddr(0));

    var xmlStr = xml.GetXml();

    // The last argument to be passed to CreateMdn will be a boolean
    // indicating whether to include the entire MIME of the calling
    // email object in the MDN, or only the header.
    // It may make sense to include the entire email for small emails,
    // but for large emails (with large attachments) it's probably
    // best to make the MDN header-only.
    var bHeaderOnly = true;

    // The first argument to be passed to CreateMdn will
    // be a human-readable explanation that will be placed
    // into the 1st MIME part of the MDN (see RFC 3798).
    var humanReadableExplanation = "Blah blah blah.  Your message has been received and displayed. Blah blah blah";

    // OK, we're ready to create MDN...
    // mdnEmail: Email
    var mdnEmail;

    mdnEmail = email.CreateMdn(humanReadableExplanation,xmlStr,bHeaderOnly);
    if (email.LastMethodSuccess == false) {
        console.log(email.LastErrorText);
        return;
    }

    // Show the MIME of the source (original) email:
    console.log(email.GetMime());

    console.log("**************************************");

    // Show the MIME of the MDN email:
    console.log(mdnEmail.GetMime());

    // Sample output showing the MIME of the original email,
    // and the MDN email created based upon it:

    // X-Account-Key: account2
    // X-UIDL: 0D154945439D42BD80F180F6D9DE4D82
    // Received: with MailEnable Postoffice Connector;
    // 	 Tue, 21 Jun 2011 09:21:23 -0400
    // Received: from qmta14.emeryville.ca.mail.comcast.net ([76.96.227.212]) by chilkatsoft.com with MailEnable ESMTP;
    // 	 Tue, 21 Jun 2011 09:21:22 -0400
    // Received: from omta03.emeryville.ca.mail.comcast.net ([76.196.30.27]) by qmta14.emeryville.ca.mail.comcast.net with comcast id yd4k1g0050b6N64AEdLW9x;
    // 	 Tue, 21 Jun 2011 13:20:30 +0000
    // Received: from [127.0.0.1] ([67.175.202.103]) by omta03.emeryville.ca.mail.comcast.net with comcast id ydLV1g00n2EMkZ78PdLWxi;
    // 	 Tue, 21 Jun 2011 13:20:31 +0000
    // Message-ID: <4E009AA4.3090205@chilkatsoft.com>
    // Date: Tue, 21 Jun 2011 08:20:36 -0500
    // From: Chilkat Software <admin@chilkatsoft.com>
    // User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
    // MIME-Version: 1.0
    // To: Chilkat Support <support@chilkatsoft.com>
    // Subject: test 123
    // Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    // Content-Transfer-Encoding: 7bit
    // Return-Path: <>
    // X-Antivirus: avast! (VPS 110621-0, 06/21/2011), Inbound message
    // X-Antivirus-Status: Clean
    // 
    // This is a test 123
    // 
    // 
    // 
    // **************************************
    // Content-Type: multipart/report;
    // 	 report-type=disposition-notification;
    // 	 boundary="------------000802010206080606030808"
    // 
    // --------------000802010206080606030808
    // Content-Type: text/plain
    // Content-Transfer-Encoding: 7bit
    // 
    // Blah blah blah.  Your message has been received and displayed. Blah blah blah
    // --------------000802010206080606030808
    // Content-Type: message/disposition-notification
    // 
    // Disposition: manual-action/MDN-sent-manually; displayed
    // Original-Message-ID: <4E009AA4.3090205@chilkatsoft.com>
    // Final-Recipient: support@chilkatsoft.com
    // 
    // --------------000802010206080606030808
    // Content-Type: text/rfc822-headers
    // 
    // X-Account-Key: account2
    // X-UIDL: 0D154945439D42BD80F180F6D9DE4D82
    // Received: with MailEnable Postoffice Connector;
    // 	 Tue, 21 Jun 2011 09:21:23 -0400
    // Received: from qmta14.emeryville.ca.mail.comcast.net ([76.96.227.212]) by chilkatsoft.com with MailEnable ESMTP;
    // 	 Tue, 21 Jun 2011 09:21:22 -0400
    // Received: from omta03.emeryville.ca.mail.comcast.net ([76.196.30.27]) by qmta14.emeryville.ca.mail.comcast.net with comcast id yd4k1g0050b6N64AEdLW9x;
    // 	 Tue, 21 Jun 2011 13:20:30 +0000
    // Received: from [127.0.0.1] ([67.175.202.103]) by omta03.emeryville.ca.mail.comcast.net with comcast id ydLV1g00n2EMkZ78PdLWxi;
    // 	 Tue, 21 Jun 2011 13:20:31 +0000
    // Message-ID: <4E009AA4.3090205@chilkatsoft.com>
    // Date: Tue, 21 Jun 2011 08:20:36 -0500
    // From: Chilkat Software <admin@chilkatsoft.com>
    // User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
    // MIME-Version: 1.0
    // To: Chilkat Support <support@chilkatsoft.com>
    // Subject: test 123
    // Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    // Content-Transfer-Encoding: 7bit
    // Return-Path: <>
    // X-Antivirus: avast! (VPS 110621-0, 06/21/2011), Inbound message
    // X-Antivirus-Status: Clean
    // --------------000802010206080606030808--
    // 
    // 

}

chilkatExample();

 

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