File size: 1,123 Bytes
fd563a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from typing import Text, Union, Iterable


def mailing_main(subject:Text, body:Text, to_address:Union[Text, Iterable[Text]]):
    """Sends the email with the given subject and body to the given address (accepts also list of addresses)."""
    # Mailing server configuration
    smtp_server = 'smtp.gmail.com.'
    smtp_port = 465
    sender_email = '[email protected]'
    sender_password = 'onyghfffdbmurjdf'
    
    # This creates the actual email message
    msg = MIMEMultipart()
    msg['From'] = sender_email
    msg['To'] = to_address
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'plain'))

    # Connects to SMTP server and then sends the actual email
    try:
        server = smtplib.SMTP(smtp_server, smtp_port)
        server.starttls()
        server.login(sender_email, sender_password)
        server.sendmail(sender_email, to_address, msg.as_string())
        server.quit()
        print("Email sent successfully!")
    except Exception as e:
        print("Error sending email:", e)