-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
68 lines (61 loc) · 2.15 KB
/
Code
File metadata and controls
68 lines (61 loc) · 2.15 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
60
61
62
63
64
65
66
67
68
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import requests
from bs4 import BeautifulSoup
import schedule
import time
# Function to send an email
def send_email(to, subject, body):
from_email = "marketing@digital-innovation.co.za" # Your email address
from_password = "M1234!@#$Digital" # Your password
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('mail.digital-innovation.co.za', 587)
server.starttls()
server.login(from_email, from_password)
server.send_message(msg)
server.quit()
# Function to scrape tech news and send email
def send_tech_news():
url = "https://www.businessinsider.com/sai" # URL of the website to scrape
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
news_items = soup.find_all(class_='titlelink')
news_list = []
for item in news_items:
title = item.text.strip()
link = item['href']
news_list.append(f"{title}: {link}")
news_body = "\n".join(news_list)
send_email(to="info@yaaseensaleh.co.za", subject="Tech News", body=news_body)
# Schedule the job to run every morning at 8:00 AM
schedule.every().day.at("12:27").do(send_tech_news)
# Keep the script running
while True:
schedule.run_pending()
time.sleep(60) # Sleep for 60 seconds
# Might be able to use this as a login for SMTP
"""
sender_email = 'your_email@example.com'
sender_password = 'your_email_password'
receiver_email = 'receiver_email@example.com'
subject = 'Test Email'
body = 'This is a test email sent from Python.'
# Create message object
msg = MIMEText(body)
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject
# Create SMTP connection
smtp_server = 'smtp.example.com' # Replace with your SMTP server address
smtp_port = 587 # Replace with your SMTP server port
smtp_username = sender_email
smtp_password = sender_password
smtp_connection = smtplib.SMTP(smtp_server, smtp_port)
smtp_connection.starttls()
smtp_connection.login(smtp_username, smtp_password)_
"""