-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_results.py
More file actions
59 lines (49 loc) · 3.63 KB
/
email_results.py
File metadata and controls
59 lines (49 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from google.auth import impersonated_credentials
from google.auth.transport.requests import Request
from google.oauth2 import service_account
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import json
# def load_credentials(json_file):
# with open(json_file) as f:
# credentials_data = json.load(f)
# return credentials_data
# def authenticate_with_google_api(json_file, scopes):
# credentials_data = load_credentials(json_file)
# credentials = service_account.Credentials.from_service_account_info(credentials_data, scopes=scopes)
# return credentials
# credentials_file = "/credentials/punnett-square-1aa9227aadb2.json"
# scopes = ['https://www.googleapis.com/auth/gmail.send']
# Email configuration
sender_email = "geneticdisorderstest@gmail.com"
password = "thkf lqih wbch bita"
# password = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJO4FAVEVx0bGq\nwNvV+bMJmzSpfGV+GxTRzIPkCw1en54Am+qW93w1wjW+PgJON/9XaHa+f/3vyRQw\nF9BFrhcP0usdG3WLWil1NACmSrdxIuE38BhnaeLF01M4bZiS1jhsccDol9JjOJAv\nsXtJJtcNLG2TMI0jkKrwTs7QuuOxFL7q+/2BQdThQQcKDdkwEYz5sC4kXeNFDYKq\nKrg0f4subvOnzWNLZajpmlnEfh8agSvYVyvlu6dpqPhSo8ws0ZU0WrS7eQWfp9+K\nYD3M3TJD9lt5z2/DgE7fEb9IBLUE+2cS8KD6wxafzbCYiOVO6VJk4pNwxdg8Bkjw\nFPAlMqe1AgMBAAECggEALNtv33gplsqosSiWmKc1ytFnNtS9BxRgWrgdOmtgSpSI\nMxiOfaKjdJRbSJIoD2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9k4zbS0XPqCf69wa6iqiCcrqwzDB\n6sqdNhC/o+aEsbOLBq/EidYg9tIyQO65T5C7NcEQTnFqfZCMqt94jiXOtFeKyBZp\nSJ2YIdin9iFBqdBIWAdLWlfy\n-----END PRIVATE KEY-----\n"
# sender_email = "geneticdisorderstest@punnett-square.iam.gserviceaccount.com"
def email_results(recipient_email, prob_dict):
sent = False
# Create a multipart message
message = MIMEMultipart()
# credentials = authenticate_with_google_api(credentials_file, scopes)
message["From"] = sender_email
message["To"] = recipient_email
message["Subject"] = "Results for Genetic Disorders"
# Add body to email
body = parse_dict(prob_dict)
print(body)
message.attach(MIMEText(body, "plain"))
# Connect to the SMTP server
with smtplib.SMTP(host="smtp.gmail.com", port=587) as server:
server.set_debuglevel(1)
server.starttls() # Start TLS encryption
server.ehlo()
server.login(sender_email, password)
text = message.as_string()
server.sendmail(sender_email, recipient_email, text)
sent = True
return sent
def parse_dict(prob_dict):
txt = ''
for key, value in prob_dict.items():
txt += 'Probability of the offspring having ' + key + ' is ' + str(value) + '%\n'
return txt