forked from filip-michalsky/SalesGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mail.py
45 lines (40 loc) · 1.51 KB
/
test_mail.py
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
import os
from salesgpt.tools import send_email_with_gmail # Adjust the import path as necessary
from dotenv import load_dotenv
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
load_dotenv()
# Set environment variables for the test
def send_simple_email(recipient_email, subject, body):
try:
sender_email = os.getenv("GMAIL_MAIL")
app_password = os.getenv("GMAIL_APP_PASSWORD")
print(sender_email)
print(app_password)
# Ensure sender email and app password are not None
if not sender_email or not app_password:
return "Sender email or app password not set."
# Create MIME message
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = recipient_email
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
# Create server object with SSL option
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender_email, app_password)
text = msg.as_string()
server.sendmail(sender_email, recipient_email, text)
server.quit()
return "Email sent successfully."
except Exception as e:
return f"Failed to send email: {e}"
# Test email details
recipient_email = "[email protected]"
subject = "Test Email"
body = "This is a test email sent from the Python script without using LLM."
# Send the test email
result = send_simple_email(recipient_email, subject, body)
print(result)