MFC Examples

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

MFC Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DKIM / DomainKey
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
// Needs #include <CkMime.h>
// Needs #include <CkMailMan.h>
// Needs #include <CkEmail.h>

    CkString strOut;

    CkMime mime;
    CkMailMan mailman;

    //  Any string argument automatically begins the 30-day trial.
    bool success;
    success = mime.UnlockComponent("30-day trial");
    if (success != true) {
        strOut.append(mime.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Any string argument automatically begins the 30-day trial.
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

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

    //  Set the SMTP login/password (if required)
    mailman.put_SmtpUsername("myUsername");
    mailman.put_SmtpPassword("myPassword");

    //  Load the MIME (or S/MIME) from a file:
    success = mime.LoadMimeFile("edifact_smime.txt");
    if (success != true) {
        strOut.append(mime.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    const char * fromAddr;
    const char * recipient;
    fromAddr = "admin@chilkatsoft.com";
    recipient = "support@chilkatsoft.com";

    //  Add email header fields to the MIME:
    mime.AddHeaderField("From",fromAddr);
    mime.AddHeaderField("To",recipient);
    mime.AddHeaderField("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:
    CkEmail email;
    const char * dateStr;
    dateStr = email.getHeaderField("Date");
    mime.AddHeaderField("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 = mime.SaveMime("email.eml");
    if (success != true) {
        strOut.append(mime.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Now send the MIME via SMTP:
    const char * mimeContent;
    mimeContent = mime.getMime();
    success = mailman.SendMime(fromAddr,recipient,mimeContent);
    if (success != true) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    success = mailman.CloseSmtpConnection();
    if (success != true) {
        strOut.append("Connection to SMTP server not closed cleanly.\r\n");
    }

    strOut.append("Mail Sent!\r\n");

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

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

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