From af0d97ef8425dba5cd87a9407dd6615d51120b2c Mon Sep 17 00:00:00 2001 From: Victor Rohlfs Date: Fri, 19 Jul 2024 14:51:23 -0400 Subject: [PATCH] Adding email example in python used for a customer demo --- .DS_Store | Bin 0 -> 6148 bytes nodejs/.DS_Store | Bin 0 -> 6148 bytes python/email_block_data.py | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .DS_Store create mode 100644 nodejs/.DS_Store create mode 100644 python/email_block_data.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2c25c3c6348690e2a8bc572f41fbc0620cf17a01 GIT binary patch literal 6148 zcmeHKI|>3p3{6x-u(7n9D|mxJ^aNf&bZtc3LhQHlTprDr4}z>Vf{naD@@6u5v+OH2 z8xhgvwONSFL}UUtl$(XV*|~Yo2ANSH9CsY$(p>hZUE7{|)$bF=9m`o-Y2@$)|NX7Z zQUNMJ1*iZOpaP#1u-*%sOamFI02QDDPX+AzP~e6&u?zH12ZE0Pz!B1JSoWZy# WUK6`Orz7ulAb$o-7aA4#wE_?NNEMg> literal 0 HcmV?d00001 diff --git a/nodejs/.DS_Store b/nodejs/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ba8e123dd70c4c8436d476d354f4713d993c0788 GIT binary patch literal 6148 zcmeHKyG{c^3>-s>NHi%^?hmBk4^~m~1^fVyOGV%y3H^2aHe;`mI2{yeC}1qvbL;c$ zYNt4#0oeMjy9O2j=5$BAdzhNPcc0irW{gPZ9z7nh!!uTRnpA(EaPAVX!8wiiJDhNb zj_$a^3*!Mt?tkcx5BvMR-#b|*1*Cu!kOERb3Y?`tw$J(1Su7Px0V(hw6!7mup*z;Z zp<#SF7-9q<&X^A4bIcON;t66+92zo1vqmL0s^y4bjm~_@x|%pNY;;%-AC@OuPAC?q zbN>?Mu-Z^j3P^#m0+(&M@czH0|1kfLNm@w(De$Khu-WEjv*wkuw@xnSy|&PA>7T~h oC})UPOpI2{g}376m%8H5d|wlXhCydO=tTVpxGpj&@EZzz0ICBS)&Kwi literal 0 HcmV?d00001 diff --git a/python/email_block_data.py b/python/email_block_data.py new file mode 100644 index 0000000..229ec8d --- /dev/null +++ b/python/email_block_data.py @@ -0,0 +1,59 @@ +''' + Important notes: + 1. Replace "your_email@example.com", "recipient@example.com", and "your_email_password" with actual values. + 2. If you're using Gmail, you might need to use an "App Password" instead of your regular password. You can set this up in your Google Account settings. + 3. The SMTP server (smtp.gmail.com) is set for Gmail. If you're using a different email provider, you'll need to change this to your provider's SMTP server. + 4. Make sure to handle the email credentials securely. Avoid hardcoding them in the script. Consider using environment variables or a secure key management system. +''' + +import json +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart + +def main(params): + # Extract dataset and network from metadata in params + dataset = params['metadata']['dataset'] + network = params['metadata']['network'] + # Extract user data from params, if any + user_data = params.get('user_data', {}) + + # Prepare email content + subject = f"Data from {dataset} dataset on {network} network" + body = json.dumps({ + 'message': f"This is data from the {dataset} dataset on the {network} network.", + 'user_data': user_data, + 'params': params + }, indent=2) + + # Email configuration + sender_email = "your_email@example.com" # Replace with your email + receiver_email = "recipient@example.com" # Replace with recipient's email + password = "your_email_password" # Replace with your email password or app-specific password + + # Create a multipart message and set headers + message = MIMEMultipart() + message["From"] = sender_email + message["To"] = receiver_email + message["Subject"] = subject + + # Add body to email + message.attach(MIMEText(body, "plain")) + + try: + # Create SMTP session + with smtplib.SMTP('smtp.gmail.com', 587) as server: # Using Gmail SMTP server, adjust if using a different provider + server.starttls() # Enable security + server.login(sender_email, password) + text = message.as_string() + server.sendmail(sender_email, receiver_email, text) + print("Email sent successfully") + except Exception as e: + print(f"Error sending email: {str(e)}") + + # Return anything that you will consume on API side or helping you check your execution later + return { + 'message': f"Email sent with data from the {dataset} dataset on the {network} network.", + 'user_data': user_data, + 'params': params + } \ No newline at end of file