| from mailjet_rest import Client | |
| import os | |
| # Optional: load from .env | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| # Your Mailjet credentials | |
| api_key = os.environ.get('MJ_API_KEY') | |
| api_secret = os.environ.get('MJ_API_SECRET') | |
| def send_email(to_email, subject, message_body, cc_emails=None, bcc_emails=None): | |
| mailjet = Client(auth=(api_key, api_secret), version='v3.1') | |
| # Build recipient objects | |
| to = [{"Email": to_email}] | |
| cc = [{"Email": email} for email in cc_emails] if cc_emails else [] | |
| bcc = [{"Email": email} for email in bcc_emails] if bcc_emails else [] | |
| data = { | |
| 'Messages': [ | |
| { | |
| "From": { | |
| "Email": "satyamrahangdale196@gmail.com", | |
| "Name": "Satyam R" | |
| }, | |
| "To": to, | |
| "Cc": cc, | |
| "Bcc": bcc, | |
| "Subject": subject, | |
| "TextPart": message_body | |
| } | |
| ] | |
| } | |
| result = mailjet.send.create(data=data) | |
| print(result.status_code) | |
| print(result.json()) | |
| return result.status_code == 200 or result.status_code == 201 | |
| # send_email( | |
| # to_email="raianand.1991@gmail.com", | |
| # subject="Test email : ASR Processing Started", | |
| # message_body="Your audio transcription has started.", | |
| # bcc_emails=["pedanticsatoshi0@getsafesurfer.com"] | |
| # ) | |