Open Adamtbraun opened 11 months ago
import whois import datetime import smtplib from email.mime.text import MIMEText
def get_domain_expiration(domain): try: whois_info = whois.whois(domain) expiration_date = whois_info.expiration_date
# If the expiration_date is a list, take the first element
if isinstance(expiration_date, list):
expiration_date = expiration_date[0]
return expiration_date
except Exception as e:
print(f"Error retrieving WHOIS information: {str(e)}")
return None
def send_email(to_address, subject, body):
sender_email = "your_email@gmail.com"
sender_password = "your_email_password"
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = to_address
try:
with smtplib.SMTP("smtp.gmail.com", 587) as server:
server.starttls()
server.login(sender_email, sender_password)
server.sendmail(sender_email, to_address, msg.as_string())
print("Email notification sent successfully.")
except Exception as e:
print(f"Error sending email: {str(e)}")
def check_domain_expiration(domain, days_before_expiry, recipient_email): expiration_date = get_domain_expiration(domain)
if expiration_date:
today = datetime.datetime.now()
days_remaining = (expiration_date - today).days
if days_remaining <= days_before_expiry:
subject = f"Domain Expiry Alert: {domain} is expiring soon"
body = f"The domain {domain} is set to expire in {days_remaining} days on {expiration_date}."
send_email(recipient_email, subject, body)
else:
print(f"{domain} is not expiring soon. {days_remaining} days remaining.")
else:
print(f"Could not retrieve expiration date for {domain}.")
check_domain_expiration('your_domain.com', 5, 'your_email@example.com')
backorder script