Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

Load MIME (or S/MIME) and Send as Email

Demonstrates how to load a MIME file and send it as email.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
#include <C_CkMime.h>
#include <C_CkMailMan.h>
#include <C_CkEmail.h>

void ChilkatSample(void)
    {
    HCkMime mime;
    HCkMailMan mailman;
    BOOL success;
    const char * fromAddr;
    const char * recipient;
    HCkEmail email;
    const char * dateStr;
    const char * mimeContent;

    mime = CkMime_Create();
    mailman = CkMailMan_Create();

    //  Any string argument automatically begins the 30-day trial.

    success = CkMime_UnlockComponent(mime,"30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    //  Any string argument automatically begins the 30-day trial.
    success = CkMailMan_UnlockComponent(mailman,"30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        return;
    }

    //  Set the SMTP server.
    CkMailMan_putSmtpHost(mailman,"smtp.chilkatsoft.com");

    //  Set the SMTP login/password (if required)
    CkMailMan_putSmtpUsername(mailman,"myUsername");
    CkMailMan_putSmtpPassword(mailman,"myPassword");

    //  Load the MIME (or S/MIME) from a file:
    success = CkMime_LoadMimeFile(mime,"edifact_smime.txt");
    if (success != TRUE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    fromAddr = "admin@chilkatsoft.com";
    recipient = "support@chilkatsoft.com";

    //  Add email header fields to the MIME:
    CkMime_AddHeaderField(mime,"From",fromAddr);
    CkMime_AddHeaderField(mime,"To",recipient);
    CkMime_AddHeaderField(mime,"Subject","Here is my EDIFACT signed and encrypted...");

    //  We want a Date header with the current date/time.  The email object
    //  automatically generates it.  Therefore we'll create an email object and then
    //  copy the Date header:
    email = CkEmail_Create();

    dateStr = CkEmail_getHeaderField(email,"Date");
    CkMime_AddHeaderField(mime,"Date",dateStr);

    //  It is not necessary to save the MIME to a file.
    //  We're doing it here just to have a look at the .eml in a text editor...
    success = CkMime_SaveMime(mime,"email.eml");
    if (success != TRUE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    //  Now send the MIME via SMTP:

    mimeContent = CkMime_getMime(mime);
    success = CkMailMan_SendMime(mailman,fromAddr,recipient,mimeContent);
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        return;
    }

    success = CkMailMan_CloseSmtpConnection(mailman);
    if (success != TRUE) {
        printf("Connection to SMTP server not closed cleanly.\n");
    }

    printf("Mail Sent!\n");

    CkMime_Dispose(mime);
    CkMailMan_Dispose(mailman);
    CkEmail_Dispose(email);

    }

Need a specific example? Send a request to support@chilkatsoft.com

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