Global Email Notebook: Databricks Reference Guide#

Notebook Configuration#

Follow the instructions to get the notebook and details about installation in Notebook Installation.

Verify Single Email#

The Verify Single Email notebook validates and standardizes an individual email address using the Global Email API. It can return the response as JSON or write selected response fields to an output table.

Example#

  1. Set up your license key using Databricks secrets. See Databricks License Key Set Up.

  2. Fill in the required fields indicated by (*).

  3. Click Run all to run the notebook.

  4. The JSON response will be displayed in the View Results notebook section. If an output table is named, the result will append to the table.

Input Example

../../_images/Databricks-Global-Email-Verify-Single-Example-Input.png

Output Example

../../_images/Databricks-Global-Email-Verify-Single-Example-Output.png

Input Parameters#

The following table describes the input parameters for the Verify Single Email notebook.

Parameter

Data Type

Description

Example

License

STRING

Required.
The License Key with Credits issued by Melissa.

Get it here.

See more information on license key set up.

Email

STRING

Required.
Email address to verify.

info@melissa.com

Options

STRING

[OptionName:Parameter], separated by commas (,).

See more information about endpoint options.
If omitted, Default Input Options will be applied.

VerifyMailbox:Express

Output Table Name

STRING

The output table name.

A new table will be created if it doesn’t exist.
If the table exists, its structure must remain unchanged.
If left blank, only the JSON response is returned.

Output Table Fields

STRING

Case-sensitive.

Only valid when Output Table Name is provided.

Select fields for the output table. If left blank or Select All, all fields will output.
To output chosen fields, ensure Select All is deselected.

RecordID,
Results,
EmailAddress,
MailboxName,
DomainName,
DomainAuthenticationStatus,
TopLevelDomain,
TopLevelDomainName,
DateChecked,
EmailAgeEstimated,
DeliverabilityConfidenceScore,
DomainAgeEstimated,
DomainExpirationDate,
DomainCreatedDate,
DomainUpdatedDate,
DomainEmail,
DomainOrganization,
DomainAddress1,
DomainLocality,
DomainAdministrativeArea,
DomainPostalCode,
DomainCountry,
DomainCountryCode,
DomainAvailability,
DomainPrivateProxy,
PrivacyFlag,
MXServer,
DomainTypeIndicator,
BreachCount,
ActivityLevel

Verify Multiple Emails#

The Verify Multiple Emails notebook processes email address records in batches, validating and standardizing key components using the Global Email API.

It can handle tables of any size, returning the results in a specified output table and supports optional fields for flexible, accurate email validation.

Requirements#

To use this notebook, you need to prepare an input table in Databricks beforehand referencing our default input fields below.

Input Fields#

Column Name

Data Type

Description

record_id

STRING

Required.
Record identifier, primary key.

email

STRING

Required.
The email address to be verified.

Python Notebook Setup#

The step-by-step example below shows how to use the notebook. Replace with your values.

  • Step 0 - Prepare an input table

    Assume that the input table has the signature below:

    CREATE TABLE IF NOT EXISTS <catalog>.<schema>.<input_table> (
       RecId INT,
       EmailAddress STRING
    );
    

    This input table has different column names from the Input Fields. Mapping column names in Step 2 is necessary for the program to get the correct parameters.

Attention

Make sure your input table contains unique RecordID before running the next script. See more about Batch Processing Best Practices.

  • Step 1 - Required Privileges

    Ensure you have the necessary access to the input table and output table including SELECT, INSERT, UPDATE, USE SCHEMA, and USE CATALOG privileges for the tables involved.

  • Step 2 - Map Input Columns with the Default Input Fields

    Set the required parameters and map your input columns to our Input Fields.

    Check Input Parameters for more information.

    from melissadatacloudapi_databricks import Config, GLOBAL_EMAIL, run
    
    config = Config(
        license_key=LICENSE_KEY,
        input_table="<catalog>.<schema>.<input_table>",
        output_table="<catalog>.<schema>.<output_table>",
        # Map your input columns with our input fields, replace with your actual column names
        parameter_mapping={
          "record_id": "RecId",
          "email": "EmailAddress",
        },
        request_parameters={
          "options": "",
        },
        output_columns="<field_1,field_2>",
        log_to_table=False,
        log_table="<catalog>.<schema>.<log_table>",
        duplicate_check=False,
    )
    
  • Step 3 - Call run() to verify your data

    run(GLOBAL_EMAIL, config, spark=spark, dbutils=dbutils)
    
    # Output table view
    display(
        spark.sql(
            f"SELECT * FROM {config.output_table} ORDER BY TRY_CAST(RecordID AS BIGINT), RecordID LIMIT 1000"
        )
    )
    

Input Parameters#

The following table describes the input parameters for the Verify Multiple Emails notebook.

Parameter

Data Type

Description

Example

license_key

STRING

Required.
The License Key with Credits issued by Melissa.

Get it here.

See more information on license key set up.

parameter_mapping

Connects each Melissa field to a column in your input table. See Input Fields.

request_parameters

Sent once with every batch, applied to every record.

options
[OptionName:Parameter], separated by commas (,).

See more information about endpoint options.
If omitted, Default Input Options will be applied.

VerifyMailbox:Express

input_table

STRING

Required.
Name of the input table.

catalog.schema.input_table_name

output_table

STRING

Required.
The output table name.

A new table will be created if it doesn’t exist.
If the table exists, its structure must remain unchanged.

catalog.schema.output_table_name

output_columns

STRING

Case-sensitive.

Fields in the output table; fields separated by commas (,) if not ‘ALL’.
Field names must match the available output column names in the example list. Use ALL to include every available field. This significantly increases the writing time to the output table, so we recommend using the default or specifying the output fields.
If omitted, see Default Output Fields.

RecordID,
InEmail,
Results,
EmailAddress,
MailboxName,
DomainName,
DomainAuthenticationStatus,
TopLevelDomain,
TopLevelDomainName,
DateChecked,
EmailAgeEstimated,
DeliverabilityConfidenceScore,
DomainAgeEstimated,
DomainExpirationDate,
DomainCreatedDate,
DomainUpdatedDate,
DomainEmail,
DomainOrganization,
DomainAddress1,
DomainLocality,
DomainAdministrativeArea,
DomainPostalCode,
DomainCountry,
DomainCountryCode,
DomainAvailability,
DomainPrivateProxy,
PrivacyFlag,
MXServer,
DomainTypeIndicator,
BreachCount,
ActivityLevel,
Response,
Timestamp

log_to_table

BOOLEAN

Enable or disable logs to facilitate troubleshooting in case of any issues.
- False (Default): No action will be taken. The notebook will process with no log writes.
- True: Enable event, batch progress, and error logging.

True

log_table

STRING

Name of the log table. Only valid when log_to_table = True.

catalog.schema.log_table_name

duplicate_check

BOOLEAN

Enable or disable several checks for duplicate RecordID.
- False (Default): No action will be taken. The notebook will process records coming from the input source as is.
- True: Enable several checks for duplicate RecordID. When enabled, a repeated RecordID stops the run before anything is sent, and records already in the output table are skipped. This makes it safe to rerun after a failure without submitting the same records to the service again.

True

Default Settings#

Default Input Options#

If input options is empty, default input options will be:

Parameter

Value

options

VerifyMailbox:Express,
TimeToWait:5,
WhoIsLookup:Off,
DomainCorrection:Off

These are our recommended service options for general batch processing. See more information about endpoint options here.

Additional output columns available only with WhoIsLookup:ON

  • DomainAgeEstimated

  • DomainExpirationDate

  • DomainCreatedDate

  • DomainUpdatedDate

  • DomainEmail

  • DomainOrganization

  • DomainAddress1

  • DomainLocality

  • DomainAdministrativeArea

  • DomainPostalCode

  • DomainCountry

  • DomainAvailability

  • DomainCountryCode

  • DomainPrivateProxy

Default Output Fields#

If output_columns is an empty string or not provided, output table will have a default schema as below.

Column Name

Data Type

RecordID

STRING

InEmail

STRING

Results

STRING

EmailAddress

STRING

EmailAgeEstimated

STRING

BreachCount

STRING

DeliverabilityConfidenceScore

STRING

DomainName

STRING

DomainTypeIndicator

STRING

MailboxName

STRING

PrivacyFlag

STRING

TopLevelDomain

STRING

TopLevelDomainName

STRING

Result Codes#

For the full list of result codes returned by Global Email Notebook: Databricks, please visit here.

Using DCS#

We recommend that most clients leverage the Deliverability Confidence Score (DCS) field for a simple way to determine email deliverability and validity. Distilling the result codes and email metadata and signals allow us to generate a simple score that will generally be more accurate than result codes alone.

Our general recommendations for using DCS are:

DCS

Marketing

Point of Entry/Form

0 to 30

Do not send email.

Do not accept email, but consider letting users override this.

31 to 60

Do not send email without additional evidence that the email is currently good.

Accept email conditionally; prompt user to double-check input.

61 to 75

Send email, unless risk tolerance for bounces is low (i.e. building or repairing sender reputation).

Accept email. Very likely to be a good email address.

76 to 100

Send email. Very likely to be a good address.

Accept email. Very likely to be a good email address.

We believe the DCS is a valuable tool to make quick decisions about email deliverability. Marketing campaigns, in particular, are often sensitive to special cases like accept-all email addresses. By themselves, result codes do not always provide a clear indication of deliverability. In such cases, relying purely on result code filters puts the efficacy of a campaign and your sender reputation at risk.

Because the DCS factors in more than just result codes, we recommend using DCS as the primary filter for validation efforts. For an example of how you might implement something like this, see the Pseudocode section below.

Pseudocode#

# Pythonic pseudocode for validating email addresses at point of entry, such as a registration form.

# A "marketing rule" which requires a DCS of 61 allows you to filter emails with a medium-high likelihood of deliverability.
DCS_MARKETING = 61
# A "minimum rule" which requires a DCS of 41 allows you to accept emails from user inputs, even though they may not be good candidates to send marketing materials to.
DCS_MINIMUM = 41

# You may want to check result codes for any special cases you would like to handle.
CORRECTION_CODES = ["ES10","ES11","ES12","ES13"] # returned when certain types of corrections were applied to the output email
ROLE_ADDRESS_CODE = "ES08" # returned for addresses like info@melissadata.com

input_email = "john.doe@melissadata.com"
is_valid = None
is_good_for_marketing = None

# Send the record to the web service and get result codes for the response. In production, be sure you handle HTTP Errors and TransmissionResults in the top level of the response body.
service_response = send_email_request(john.doe@melissadata.com)
response_record = service_response["Records"][0]
corrected_email = response_record["EmailAddress"] # It is important to use the output email since Global Email can correct typos.

# Check validity and deliverability of the email address using the DCS.
if(response_record["DeliverabilityConfidenceScore"] >= DCS_MINIMUM):
  is_valid = True
elif(response_record["DeliverabilityConfidenceScore"] > 0):
  is_valid = True
  prompt_user("This email address appears to be invalid. Are you sure you’d like to use this email address?")
elif(response_record["DeliverabilityConfidenceScore"] == 0):
  is_valid = False
  prompt_user("This email address appears to be invalid. Please enter a valid email address.")

# Check to see if the email was corrected.
# If this is on a registration form, consider prompting your user to accept/reject the correction.
if(response_record["Results"].containsAnyOf(CORRECTION_CODES)):
  corrected_email = service_response["EmailAddress"]
  user_message = f"We detected a likely typo in your email address. Did you mean ${corrected_email}?"
  prompt_user(user_message)

# Check for special codes like Role Addresses depending on use case.

# For example, if you prefer the user's personal address and not an email group, you might choose to reject these or require confirmation from the user.
if(response_record["Results"].contains(ROLE_ADDRESS_CODE)):
  handle_role_address(corrected_email)

# Check if the email address is likely to be deliverable, and thus a good marketing candidate, using the DCS.
if(response_record["DeliverabilityConfidenceScore"] >= DCS_MARKETING):
  is_good_for_marketing = True
  include_in_marketing_campaign(corrected_email)

Interpreting Result Codes#

Result codes yield more granular information about a given email. They are returned as a comma-delimited string of 4-character alpha-numeric codes, e.g. ES01,ES07,ES21 or EE04,ES22.

The SE## and GE## codes (Transmission Service Error and General Transmission Error) are used to signify more general errors, and are returned under the key TransmissionResults in the outermost level of our responses.

The ES## and EE## codes (Email Status and Email Error) are returned alongside each email record in a response.

The ES37 result code enhances both internal and client security by identifying potentially compromised email accounts. However, it’s important to note that the Breach Flag is not intended as an anti-fraud measure. Emails marked with an ES37 code should not be dismissed as fraudulent solely based on this flag. Instead, the code serves as a warning flag, prompting additional monitoring or two-factor authentication (2FA) for the affected email address.

Using Result Codes (Advanced)#

While Deliverability Confidence Score (DCS) can help you understand if an email is “good” to send to, result codes can be used to get more specific information about validation results.

Looking for exact matches between two result code strings could lead to misinterpretations. The same underlying outcome can be expressed through different result code combinations. For example, a valid email might return any of the following: ES01,ES22, ES01,ES10,ES22, or ES01,ES10,ES12,ES22. In each case, the email is valid, but the API made different corrections to the input. Setting up business logic for when only a specific combination is found may result in improper handling.

By using DCS first (described in above sections) and interpreting result codes when more information is needed, implementation is simplified and the addition or removal of any result codes will not affect your processes. While changes in result codes are rare outside of major releases, this is the most future proof approach to handle results.

For example, the result code ES02 was deprecated after Global Email version 3. However, even with version 3, any email that came back with ES02 always had at least one EE## code (e.g. ES02,EE04). Any implementation that was looking for a high DCS score or an EE## code independently of ES02 would have been forward compatible; those relying on specific combinations would have broken.

We strongly recommend using DCS instead of interpreting every result code to determine validity. However, if result codes are to be interpreted to determine acceptance criteria, it is often best to use cascading logic.

Since multiple codes can be returned in a single response, it’s important to process them in order of priority to ensure accurate handling. For instance, if an email returns ES01,ES05,ES22, the ES05 should be addressed before ES01 as it indicates a more critical status to check.

How you choose to act on each code will depend on your specific use case. Typically, once you identify that an email is invalid (EE##) or contains a set of undesirable result code(s), then you shouldn’t need to evaluate those results further.

The following table shows the most common result codes seen while using Global Email and our recommendations for how to interpret them. The codes are ordered by priority – meaning you should filter for and handle the codes higher on the list before those lower down.

Code

Description

Recommendation for Marketing

Recommendation for Point of Entry

EE01

Email Syntax Error

Reject

Reject

EE02

Email Domain Not Found

Reject

Reject

EE03

Email Server Not Found

Reject

Reject

EE04

Invalid Email

Reject

Reject

ES04

Mobile Email Address

Reject

Reject

ES05

Disposable Domain

Reject

Caution

ES06

Spamtrap Domain

Reject

Accept

ES36

Spamtrap Mailbox

Reject

Accept

ES08

Role Address

Caution

Accept

ES09

Protected Mailbox Caution

Caution

Accept

ES07

Accept All Server

Caution

Accept

ES31

Suspicious Characters

Caution

Accept

ES03

Unknown Email

Caution

Accept

ES01

Correct Email Syntax and Domain

Accept

Accept