Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Email Object
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Verify Email Addresses with VerifyRecipients

Verify email recipients. This example demonstrates the usage of the VerifyRecipients method.

Please see this blog post for more information VerifyRecipients -- Validating Email Addresses

Download Chilkat Java Library

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[])
  {
    //  The mailman object is used for sending and receiving email.
    CkMailMan mailman = new CkMailMan();

    //  Any string argument automatically begins the 30-day trial.
    boolean success;
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println("Component unlock failed");
        return;
    }

    //  Set the SMTP server.
    //  This code was tested against both mail.chilkatsoft.com
    //  and smtp.comcast.net

    //  mailman.SmtpHost = "mail.chilkatsoft.com";
    //  mailman.SmtpUsername = "admin@chilkatsoft.com";
    //  mailman.SmtpPassword = "****";

    mailman.put_SmtpHost("smtp.comcast.net");

    //  Create an email object.
    //  We'll never actually send this email.  It's only used
    //  to test the recipients.
    CkEmail email = new CkEmail();

    email.put_Subject("This is a test");
    email.put_Body("This is a test");
    email.put_From("Chilkat Support <support@chilkatsoft.com>");

    //  Add recipients to be checked.
    //  (When this was tested, a_real_person was replaced with
    //  a valid email address.)
    email.AddTo("A Real Person","a_real_person@comcast.net");
    email.AddTo("Testing","doesNotExist7434@comcast.net");
    email.AddTo("Admin","admin@chilkatsoft.com");
    email.AddTo("Not Exist","doesNotExist@chilkatsoft.com");
    email.AddCC("Not Exist","DoesNotExist7213@gmail.com");
    email.AddBcc("Exists","chilkat.support@gmail.com");

    //  NOTE: A mail server can only verify the email addresses
    //  specific to it's domain.  Therefore, when using smtp.comcast.net,
    //  only comcast.net email addresses will be flagged as invalid,
    //  and when using mail.chilkatsoft.com, only chilkatsoft.com
    //  email addresses are flagged as invalid.

    //  Add all bad email addresses to saBadAddrs:
    CkStringArray saBadAddrs = new CkStringArray();
    success = mailman.VerifyRecipients(email,saBadAddrs);
    if (success != true) {
        System.out.println(mailman.lastErrorText());

    }
    else {
        //  List the invalid email addresses:
        if (saBadAddrs.get_Count() > 0) {
            int i;
            int n;
            n = (int) saBadAddrs.get_Count();
            for (i = 0; i <= n - 1; i++) {
                System.out.println(saBadAddrs.getString(i));
            }

            //  Examine the SMTP session log to see how the email
            //  addresses were caught:
            System.out.println(mailman.smtpSessionLog());
        }
    }

  }
}

 

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

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