Пращане на мейл с Python
здравейте някой може ли да помогне като каже от къде идва грешката и как бих могъл да я оправя
import smtplib from datetime import datetime from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText # Fill in credentials here # Make sure you have enabled access to less secure apps in your google profile. You can do it from here # myaccount.google.com/lesssecureapps credentials = {'username': '', 'password': ''} # Start connection server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() # Log in to the server server.login(credentials['username'], credentials['password']) # Build message message = MIMEMultipart() message['Subject'] = 'Demo Mail' message['From'] = '' message['To'] = '' message_text = f'Hello! This email is sent from demo! {datetime.now()}' body = MIMEText(message_text) message.attach(body) # Send the mail server.send_message(message) print('Mail sent!')
Това е грешката която дава и на credentials не съм поставил username и password умишлено дава същото като ги сложа
C:\Users\teodor\Desktop\Learn\venv\Scripts\python.exe C:/Users/teodor/Desktop/Learn/mail.py
Traceback (most recent call last):
File "C:/Users/teodor/Desktop/Learn/mail.py", line 1, in <module>
import smtplib
File "C:\Users\teodor\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 47, in <module>
import email.utils
File "C:\Users\teodor\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 33, in <module>
from email._parseaddr import quote
File "C:\Users\teodor\AppData\Local\Programs\Python\Python38-32\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "C:\Users\teodor\Desktop\Learn\calendar.py", line 1
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
^
SyntaxError: invalid syntax
Process finished with exit code 1