jebin2 commited on
Commit
1273f44
·
1 Parent(s): 050d8f8

gmail server

Browse files
Files changed (3) hide show
  1. auth_utils.py +10 -2
  2. requirements.txt +1 -0
  3. test_email_env.py +37 -0
auth_utils.py CHANGED
@@ -10,11 +10,19 @@ import os
10
  # Configure logging
11
  logger = logging.getLogger(__name__)
12
 
 
13
  # Email configuration
14
  SMTP_SERVER = os.getenv("SMTP_SERVER", "127.0.0.1")
15
  SMTP_PORT = int(os.getenv("SMTP_PORT", "1025"))
16
- SMTP_USERNAME = os.getenv("SMTP_USERNAME", "sender@domain.com")
17
- SMTP_PASSWORD = os.getenv("SMTP_PASSWORD", "yourpassword")
 
 
 
 
 
 
 
18
  SMTP_SENDER = os.getenv("SMTP_SENDER", SMTP_USERNAME)
19
 
20
  def verify_password(plain_password: str, hashed_password: str) -> bool:
 
10
  # Configure logging
11
  logger = logging.getLogger(__name__)
12
 
13
+ # Email configuration
14
  # Email configuration
15
  SMTP_SERVER = os.getenv("SMTP_SERVER", "127.0.0.1")
16
  SMTP_PORT = int(os.getenv("SMTP_PORT", "1025"))
17
+ # Prioritize EMAIL_ID and EMAIL_PASSWORD if available
18
+ SMTP_USERNAME = os.getenv("EMAIL_ID") or os.getenv("SMTP_USERNAME", "sender@domain.com")
19
+ SMTP_PASSWORD = os.getenv("EMAIL_PASSWORD") or os.getenv("SMTP_PASSWORD", "yourpassword")
20
+
21
+ # Auto-configure for Gmail if using defaults and gmail address
22
+ if SMTP_SERVER == "127.0.0.1" and "gmail.com" in SMTP_USERNAME:
23
+ SMTP_SERVER = "smtp.gmail.com"
24
+ SMTP_PORT = 465
25
+
26
  SMTP_SENDER = os.getenv("SMTP_SENDER", SMTP_USERNAME)
27
 
28
  def verify_password(plain_password: str, hashed_password: str) -> bool:
requirements.txt CHANGED
@@ -9,3 +9,4 @@ httpx>=0.25.0
9
 
10
  passlib[bcrypt]>=1.7.4
11
  email-validator>=2.0.0
 
 
9
 
10
  passlib[bcrypt]>=1.7.4
11
  email-validator>=2.0.0
12
+ python-dotenv>=1.0.0
test_email_env.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+ from dotenv import load_dotenv
4
+
5
+ # Load environment variables from .env file immediately
6
+ load_dotenv()
7
+
8
+ from auth_utils import send_email
9
+
10
+ # Configure logging
11
+ logging.basicConfig(level=logging.INFO)
12
+ logger = logging.getLogger(__name__)
13
+
14
+ def test_email_sending():
15
+ email_id = os.getenv("EMAIL_ID")
16
+ if not email_id:
17
+ logger.error("EMAIL_ID not found in environment variables.")
18
+ return
19
+
20
+ logger.info(f"Testing email sending to {email_id}...")
21
+
22
+ # Debug config
23
+ from auth_utils import SMTP_SERVER, SMTP_PORT
24
+ logger.info(f"Using SMTP Server: {SMTP_SERVER}:{SMTP_PORT}")
25
+
26
+ subject = "Test Email from API Gateway"
27
+ body = "This is a test email to verify that the email credentials in .env are working correctly."
28
+
29
+ success = send_email(email_id, subject, body)
30
+
31
+ if success:
32
+ logger.info("Email sent successfully!")
33
+ else:
34
+ logger.error("Failed to send email.")
35
+
36
+ if __name__ == "__main__":
37
+ test_email_sending()