#!/usr/bin/env python3 import sys, os, smtplib, subprocess from email.message import EmailMessage from datetime import datetime GMAIL_USER = "myronblair@gmail.com" GMAIL_PASS = "demsvdylwweacbcx" def main(): if len(sys.argv) < 4: print("usage: fax-to-email.py ") sys.exit(1) tiff_path = sys.argv[1] to_email = sys.argv[2] caller_id = sys.argv[3] if not os.path.exists(tiff_path): print(f"tiff not found: {tiff_path}") sys.exit(1) pdf_path = tiff_path.rsplit(".", 1)[0] + ".pdf" subprocess.run(["tiff2pdf", "-o", pdf_path, tiff_path], check=True) msg = EmailMessage() msg["Subject"] = f"Fax received from {caller_id} - {datetime.now().strftime('%Y-%m-%d %H:%M')}" msg["From"] = GMAIL_USER msg["To"] = to_email msg.set_content(f"You received a fax from {caller_id}. See attached PDF.") with open(pdf_path, "rb") as f: msg.add_attachment(f.read(), maintype="application", subtype="pdf", filename=os.path.basename(pdf_path)) with smtplib.SMTP_SSL("smtp.gmail.com", 465) as s: s.login(GMAIL_USER, GMAIL_PASS) s.send_message(msg) print(f"Sent fax email to {to_email}") if __name__ == "__main__": main()