fracapuano commited on
Commit
fd563a8
1 Parent(s): 51fe9d2

add: mailing scripts to accepts suggestions

Browse files
Files changed (2) hide show
  1. mailing/__init__.py +1 -0
  2. mailing/mailing.py +32 -0
mailing/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .mailing import *
mailing/mailing.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import smtplib
2
+ from email.mime.text import MIMEText
3
+ from email.mime.multipart import MIMEMultipart
4
+ from typing import Text, Union, Iterable
5
+
6
+
7
+ def mailing_main(subject:Text, body:Text, to_address:Union[Text, Iterable[Text]]):
8
+ """Sends the email with the given subject and body to the given address (accepts also list of addresses)."""
9
+ # Mailing server configuration
10
+ smtp_server = 'smtp.gmail.com.'
11
+ smtp_port = 465
12
+ sender_email = '[email protected]'
13
+ sender_password = 'onyghfffdbmurjdf'
14
+
15
+ # This creates the actual email message
16
+ msg = MIMEMultipart()
17
+ msg['From'] = sender_email
18
+ msg['To'] = to_address
19
+ msg['Subject'] = subject
20
+ msg.attach(MIMEText(body, 'plain'))
21
+
22
+ # Connects to SMTP server and then sends the actual email
23
+ try:
24
+ server = smtplib.SMTP(smtp_server, smtp_port)
25
+ server.starttls()
26
+ server.login(sender_email, sender_password)
27
+ server.sendmail(sender_email, to_address, msg.as_string())
28
+ server.quit()
29
+ print("Email sent successfully!")
30
+ except Exception as e:
31
+ print("Error sending email:", e)
32
+