Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Java) Create a Multipart-Mixed MIME MessageCreates a multipart-mixed MIME message with the 1st part containing plain-text, and the 2nd part containing a GIF image.
import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkMime mime = new CkMime(); // Initialize a multipart-mixed MIME message: boolean success = mime.NewMultipartMixed(); // Each sub-part will be prepared, then added to the // top-level multipart/mixed MIME object, and then written // to a file. // First the plain-text sub-part // Add a few header fields: CkMime textPart = new CkMime(); success = textPart.AddHeaderField("Description","this is a test"); success = textPart.AddHeaderField("MyId","123"); success = textPart.SetBodyFromPlainText("This is the plain-text body"); // Now for a GIF image: CkMime imagePart = new CkMime(); success = imagePart.SetBodyFromFile("starfish.gif"); if (success == false) { System.out.println(imagePart.lastErrorText()); return; } // Append each sub-part to the top-level MIME object: success = mime.AppendPart(textPart); success = mime.AppendPart(imagePart); // Write the full multipart-mixed MIME to a file. success = mime.SaveMime("out.mim"); if (success == false) { System.out.println(mime.lastErrorText()); return; } System.out.println(mime.getMime()); // The MIME should look something like this: // (See more comments following this sample output...) // Content-Type: multipart/mixed; // boundary="------------080503030004040303020208" // // This is a multi-part message in MIME format. // // --------------080503030004040303020208 // Description: this is a test // MyId: 123 // Content-Type: text/plain // Content-Transfer-Encoding: 7bit // // This is the plain-text body // --------------080503030004040303020208 // Content-Disposition: attachment; filename="starfish.gif" // Content-Transfer-Encoding: base64 // Content-Type: image/gif; name="starfish.gif" // // R0lGODlhIAAgAPcAAP///+/v7/f39+/n5/fv7//39/fn597OzufW1tbGxs69vffe3u/W1salpZQQ // EIQYEJwQCJQYCJwYCM6clL2Ee5wpGIwhEK0YANatpdalnHMYCKUhCJQYAKUYAM6Ec5QhCJwhCPfW // zu/Oxta1rb17a6UhAK0hAPe9rb2Ec7V7a71rUpwpCL0xCJwhAOfOxta9tcatpdallM6cjMaUhK1C // IZwxELU5EK0xCLUxCN61pcacjK1rUrVaOaVKKZxCIZwxCKUxCL05CLUxAM6llO+1nMZzUr1rSrVS // KaVCGK1CGLVCEJQxCK05CLU5CIwpAKUxAK0xAM69tffWxrVrSrVaMbVKGMZKEL1CCLU5AP/v597O // xufGtcallNaljLWEa96ce9aUc717Wq1aMcZjMbVaKbVSIa1KGL1SGJw5CK1CCLVCCMZKCM5KCMZC // APfn3tbGvc57Ss5aGMZSENZaEL1KCM5SCLVCAMZKAPfezvfOte/GrdatlN6cc9aEUr1rOc5jIdZj // GL1SEM5aELVKCMZSCNZaCL1KAOfOvc57Qs5jGNZjEM5aCMZSAN5aAO/OtefGrcZjGM5jEN5rELVS // CMZaCN5jCOdrCM5aAO/Gpc5rGMZjENZrEN5jAOdrAOfe1t6MQtZ7Kd57IdZzGM5rEMZjCNZrCM5j // ANbOxu/Wve+9jPe9hO+1e+etc85zGO+EGMZrENZzEM5rCN5zCO97COdzAO/n3u+1c+ecSt6UQs57 // Ie+MIdZ7GOeEGM5zEO+EELVjCOd7CO+ECOd7AO/Ope+tWuelUu+UKeeMGOeEEO+MEOeECO+EAO/G // jO+cKfeUEO+MCO+tSuecMeeUGN6MEOeMCO+UCO+tQuelOe+lMe+lKe+cGOeUEO+cEOeUCN6MAO+U // AOe9c/e1Oe+lId6UEO+cCPe9Qve1Me+lEOecCO+lCOe1Su+1OeelGO+tGPetCPetAO+9Qve1GO+1 // EPe9CPe9APf37+fv5/f//+/v9/fv9+fe5+/e5869xufW3t7GzgAAACwAAAAAIAAgAAAI/wABCBxI // sKDBgwgTFgCwMKHDhwyHYWoIsWIBZsdyHaoIcaGbaNQ0ZeBYEROvV0pmCCDp8B4rZaOUcGHpcIEx // aqPMYLjHMcsCAwgxkRv3q8wLnhAdfWpmDRwqAgQFEEvHLlCZNxwfpVmkDJ04dczc3LsXQtq4XWh8 // aGH48F49FDUC9UInT941W6luCUOWyQmSLST3eUnChNS4c9SooQuGDNkrIIrA1MqXr0A+AyFC4Kln // kMAQKljotJJGDZklS9PkyEHGLZu1ctbCmWvXThurfAbvHSii5kegxpYqtRpEKFnid/TSneu2LRYh // P/0Q1tJRgYOZV71UL5LEK1KiV68yVf+xgaOKmAZICd5bmA8FEyZQlMjRRAhQGQv4QQSJL8ZLFHwP // 6aFIJXNIEkggcgQhwYIlKEFFGDKcEgBCBVCkByC0IAMJGnSAYsUNEmzAgw4HBJBeQisZcAswjqGh // wQeBKGIFFD0ocCJE9diyjTKRLPHBAx/cEAcdgxgx4Vg3HnSPKs4E00sNEYDwgQksQDLJIohMSJIj // ugSTCRA/ILFDCjTckUkrpYiCAEluYCMLJCsoMQUM9gjQRSSL7CLJJjmQxMw3kQChxA78IFULHIK0 // MgonXyR5UAHWVBKIEmEcUJAIYxgSSSF94AZRPrgsQgUF0RmUgWpy/LFmRYdMkACAANwrWA8cbAhi // RZ8cjRWro0QEEsQVGTiKkLAM5QNGFWrAQFNLBIzABQPLRktQQAA7 // // --------------080503030004040303020208-- // // // To explicitly set the boundary, set the Boundary property, like this: mime.put_Boundary("SOME_UNIQUE_BOUNDARY_STRING"); // To eliminate the "This is a multi-part message in MIME format." // from the output, set the UseMmDescription property = false mime.put_UseMmDescription(false); System.out.println(mime.getMime()); // The MIME now looks like this: // Content-Type: multipart/mixed; // boundary="SOME_UNIQUE_BOUNDARY_STRING" // // --SOME_UNIQUE_BOUNDARY_STRING // Description: this is a test // MyId: 123 // Content-Type: text/plain // Content-Transfer-Encoding: 7bit // // This is the plain-text body // --SOME_UNIQUE_BOUNDARY_STRING // Content-Disposition: attachment; filename="starfish.gif" // Content-Transfer-Encoding: base64 // Content-Type: image/gif; name="starfish.gif" // // R0lGODlhIAAgAPcAAP///+/v7/f39+/n5/fv7//39/fn597OzufW1tbGxs69vffe3u/W1salpZQQ // EIQYEJwQCJQYCJwYCM6clL2Ee5wpGIwhEK0YANatpdalnHMYCKUhCJQYAKUYAM6Ec5QhCJwhCPfW // zu/Oxta1rb17a6UhAK0hAPe9rb2Ec7V7a71rUpwpCL0xCJwhAOfOxta9tcatpdallM6cjMaUhK1C // IZwxELU5EK0xCLUxCN61pcacjK1rUrVaOaVKKZxCIZwxCKUxCL05CLUxAM6llO+1nMZzUr1rSrVS // KaVCGK1CGLVCEJQxCK05CLU5CIwpAKUxAK0xAM69tffWxrVrSrVaMbVKGMZKEL1CCLU5AP/v597O // xufGtcallNaljLWEa96ce9aUc717Wq1aMcZjMbVaKbVSIa1KGL1SGJw5CK1CCLVCCMZKCM5KCMZC // APfn3tbGvc57Ss5aGMZSENZaEL1KCM5SCLVCAMZKAPfezvfOte/GrdatlN6cc9aEUr1rOc5jIdZj // GL1SEM5aELVKCMZSCNZaCL1KAOfOvc57Qs5jGNZjEM5aCMZSAN5aAO/OtefGrcZjGM5jEN5rELVS // CMZaCN5jCOdrCM5aAO/Gpc5rGMZjENZrEN5jAOdrAOfe1t6MQtZ7Kd57IdZzGM5rEMZjCNZrCM5j // ANbOxu/Wve+9jPe9hO+1e+etc85zGO+EGMZrENZzEM5rCN5zCO97COdzAO/n3u+1c+ecSt6UQs57 // Ie+MIdZ7GOeEGM5zEO+EELVjCOd7CO+ECOd7AO/Ope+tWuelUu+UKeeMGOeEEO+MEOeECO+EAO/G // jO+cKfeUEO+MCO+tSuecMeeUGN6MEOeMCO+UCO+tQuelOe+lMe+lKe+cGOeUEO+cEOeUCN6MAO+U // AOe9c/e1Oe+lId6UEO+cCPe9Qve1Me+lEOecCO+lCOe1Su+1OeelGO+tGPetCPetAO+9Qve1GO+1 // EPe9CPe9APf37+fv5/f//+/v9/fv9+fe5+/e5869xufW3t7GzgAAACwAAAAAIAAgAAAI/wABCBxI // sKDBgwgTFgCwMKHDhwyHYWoIsWIBZsdyHaoIcaGbaNQ0ZeBYEROvV0pmCCDp8B4rZaOUcGHpcIEx // aqPMYLjHMcsCAwgxkRv3q8wLnhAdfWpmDRwqAgQFEEvHLlCZNxwfpVmkDJ04dczc3LsXQtq4XWh8 // aGH48F49FDUC9UInT941W6luCUOWyQmSLST3eUnChNS4c9SooQuGDNkrIIrA1MqXr0A+AyFC4Kln // kMAQKljotJJGDZklS9PkyEHGLZu1ctbCmWvXThurfAbvHSii5kegxpYqtRpEKFnid/TSneu2LRYh // P/0Q1tJRgYOZV71UL5LEK1KiV68yVf+xgaOKmAZICd5bmA8FEyZQlMjRRAhQGQv4QQSJL8ZLFHwP // 6aFIJXNIEkggcgQhwYIlKEFFGDKcEgBCBVCkByC0IAMJGnSAYsUNEmzAgw4HBJBeQisZcAswjqGh // wQeBKGIFFD0ocCJE9diyjTKRLPHBAx/cEAcdgxgx4Vg3HnSPKs4E00sNEYDwgQksQDLJIohMSJIj // ugSTCRA/ILFDCjTckUkrpYiCAEluYCMLJCsoMQUM9gjQRSSL7CLJJjmQxMw3kQChxA78IFULHIK0 // MgonXyR5UAHWVBKIEmEcUJAIYxgSSSF94AZRPrgsQgUF0RmUgWpy/LFmRYdMkACAANwrWA8cbAhi // RZ8cjRWro0QEEsQVGTiKkLAM5QNGFWrAQFNLBIzABQPLRktQQAA7 // // --SOME_UNIQUE_BOUNDARY_STRING-- } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.