SmartCheck Integration with Gmail
Certify your Gmail emails directly from the server using SmartCheck
SmartCheck is a feature of Code Contract that allows you to generate unique, secure, and tamper-proof digital evidence in just seconds, at an affordable cost.
One of its most common applications is email certification. Below, we explain how to register and certify emails from Gmail using SmartCheck:
Step 1: Obtain the Authentication Token
To use the SmartCheck API, you must first authenticate via a POST request to obtain a JWT Token.
Authentication Request (HTTP Request)
POST /login HTTP/1.1
Host: api.codecontract.io
Content-Type: application/json
{
"email": "[email protected]",
"password": "your_password"
}
Expected Response
HTTP/1.1 200 OK
Content-Type: application/json
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
Important:
✔️ The returned token must be stored and included in every subsequent request as a Bearer Token in the Authorization header.
✔️ If Gmail uses OAuth for authentication, you must first obtain an OAuth token and pass it to SmartCheck.
Step 2: Certify Emails with SmartCheck
Once authenticated, you can send the content of an email to be certified on the blockchain.
Example: Certify a Gmail Email
Use the Gmail API to retrieve an email’s content and send it to SmartCheck.
1️⃣ Retrieve the Email using Gmail API (Python Example)
from googleapiclient.discovery import build
from google.oauth2 import service_account
SCOPES = ["https://www.googleapis.com/auth/gmail.readonly"]
SERVICE_ACCOUNT_FILE = "credentials.json"
def get_gmail_email(email_id):
""" Retrieves a Gmail email by its ID """
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES
)
service = build("gmail", "v1", credentials=creds)
message = service.users().messages().get(userId="me", id=email_id).execute()
email_body = message["snippet"]
return email_body
2️⃣ Send the Email Content to SmartCheck for Certification
import requests
def certify_email(email_content):
""" Sends email content to SmartCheck for certification """
url = "https://api.codecontract.io/smartcheck/createTreeAndRegisterMerkleRoot"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
}
payload = {
"data": [email_content]
}
response = requests.post(url, json=payload, headers=headers)
return response.json()
# Get email from Gmail and certify it
email_content = get_gmail_email("EMAIL_ID")
certification_response = certify_email(email_content)
print("Certification response:", certification_response)
Expected Response
{
"merkleRoot": "abc123...",
"transactionId": "tx123...",
"status": "success"
}
What does this mean?
✔️ merkleRoot: Merkle root generated from the email content.
✔️ transactionId: Blockchain transaction ID.
✔️ status: Indicates whether the certification was successful.
Step 3: Verify a Certified Email
If you need to check whether an email has already been certified, you can query the proof in SmartCheck.
Request to Retrieve Certification Details
GET /smartcheck/reportsProofDetail?reportId=your_report_id HTTP/1.1
Host: api.codecontract.io
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Expected Response
{
"reportId": "your_report_id",
"merkleRoot": "abc123...",
"data": [
"certified email"
],
"status": "verified"
}
Summary
✔️ Step 1: Obtain the JWT Token by authenticating with your Gmail account.
✔️ Step 2: Use the Gmail API to retrieve the email content.
✔️ Step 3: Send the content to SmartCheck to certify it on the blockchain.
✔️ Step 4: Verify the certification as needed.
If you need more information or support, feel free to contact the Code Contract team. 🚀
