Authorisation Denied Accessing macOS ~/Library/Mail/V10/MailData/Envelope Index
1
vote
0
answers
44
views
I'm trying to write an AI agent to chat with my mail. The first step is access to the mail items themselves.
AppleScript was too slow, so I'm trying to use Python and Sqlite with the code below
import os
import sqlite3
# Function to connect to the Mail app's SQLite database
def connect_to_mail_db():
mail_db_path = os.path.expanduser('~/Library/Mail/V10/MailData/Envelope Index')
conn = sqlite3.connect(mail_db_path)
return conn
# Function to fetch email details
def fetch_email_details(conn):
return
# Main script
if __name__ == "__main__":
# Connect to the Mail app's database
conn = connect_to_mail_db()
# Close the database connection
conn.close()
However this is giving an authorisation error.
~/PythonProjects/email_rag ❯ /Users//.pyenv/versions/3.13.1/envs/email_rag/bin/python /Users//PythonProjects/email_rag/export_email_via_sql.py email_rag 3.13.1 system
Traceback (most recent call last):
File "/Users//PythonProjects/email_rag/export_email_via_sql.py", line 14, in
conn = connect_to_mail_db()
File "/Users//PythonProjects/email_rag/export_email_via_sql.py", line 6, in connect_to_mail_db
conn = sqlite3.connect(mail_db_path)
sqlite3.DatabaseError: authorization denied
I can access the database in terminal with
$ sqlite3 Envelope\ Index
and I can access the database with **Native Sqlite Manager**
I suspected SIP, but the fact that **Native** can access the DB would suggest otherwise.
Anyone using code to access the Apple mail.app database?
Asked by Andy S
(11 rep)
Jan 21, 2025, 03:46 AM