#🔒 why doesn't it work and gives an error?P.S this code should take my zip file and send it to me by

27 messages · Page 1 of 1 (latest)

sharp echo
#
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

server_address = "smtp.gmail.com"
server_port = 587
login, password = "#hidden", "#hidden![mem](https://cdn.discordapp.com/emojis/983393490186670121.webp?size=128 "mem") ![FUUU](https://cdn.discordapp.com/emojis/1308127428454912112.webp?size=128 "FUUU") "

msg = MIMEMultipart()
msg['From'], msg['To'], msg['Subject'] = "your_email", "recipient_email", "Тема вашего письма"
msg.attach(MIMEText("Содержимое письма", 'plain'))

file_path = "C:\\Users\\Test\\OneDrive\\Desktop\\recording.zip"

with open(file_path, "rb") as file:
    part = MIMEBase('application', 'octet-stream')
    part.set_payload(file.read())
    encoders.encode_base64(part)
    part.add_header('Content-Disposition', f"attachment; filename={file_path}")

msg.attach(part)
with smtplib.SMTP(server_address, server_port) as server:
    server.starttls()
    server.login(login, password)
    server.send_message(msg) 
swift zealotBOT
#

@sharp echo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sharp echo
#

the error is like this (PS C:\Users\Test\OneDrive\Desktop\cartridge> & C:/Users/Test/AppData/Local/Programs/Python/Python313/python.exe c:/Users/Test/OneDrive/Desktop/cartridge /main4.py
Traceback (most recent call last):
File "c:\Users\Test\OneDrive\Desktop\cartridge\main4.py", line 27, in <module>
server.send_message(msg)
~~~~~~~~~~~~~~~~~~~^^^^^
File "C:\Users\Test\AppData\Local\Programs\Python\Python313\Lib\smtplib.py", line 975, in send_message
return self.sendmail(from_addr, to_addrs, flatmsg, mail_options,
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^
rcpt_options)
^^^^^^^^^^^^^
File "C:\Users\Test\AppData\Local\Programs\Python\Python313\Lib\smtplib.py", line 876, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (552, b"5.3.4 Your message exceeded Google's message size limits. To view our\n5.3.4 message size guidelines, go to\n5.3.4 https://support.google.com/mail/? p=MaxSizeError 2adb3069b0e04-53e44a45769sm2062888e87.60 - gsmtp", 'your_email')
PS C:\Users\Test\OneDrive\Desktop\cartridge>)

river fog
sharp echo
#

why doesn't it work and gives an error?

#

does not send the file

river fog
#

Did you read the error?

sharp echo
river fog
#

Did you? It tells you exactly what the problem is.

#

It even gives you a link that has more information.

sharp echo
#

thank you

#

PS C:\Users\Test\OneDrive\Desktop\патрон> & C:/Users/Test/AppData/Local/Programs/Python/Python313/python.exe c:/Users/Test/OneDrive/Desktop/патрон/main4.py
File "c:\Users\Test\OneDrive\Desktop\патрон\main4.py", line 15
file_path = "C:\Users\Test\OneDrive\Desktop\патрон\recording.zip"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
PS C:\Users\Test\OneDrive\Desktop\патрон>

#

new error

river fog
#

\U is a special character which indicates that the characters that follow it represent a unicode character code. You need to either use // slashes, or a raw string: r"C:\Users..." (note the r).

sharp echo
sharp echo
# sharp echo Neither one nor the other method did not work and there are errors (the same)

PS C:\Users\Test\OneDrive\Desktop\патрон> & C:/Users/Test/AppData/Local/Programs/Python/Python313/python.exe c:/Users/Test/OneDrive/Desktop/патрон/main4.py
Traceback (most recent call last):
File "c:\Users\Test\OneDrive\Desktop\патрон\main4.py", line 27, in <module>
server.send_message(msg)
~~~~~~~~~~~~~~~~~~~^^^^^
File "C:\Users\Test\AppData\Local\Programs\Python\Python313\Lib\smtplib.py", line 975, in send_message
return self.sendmail(from_addr, to_addrs, flatmsg, mail_options,
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
rcpt_options)
^^^^^^^^^^^^^
File "C:\Users\Test\AppData\Local\Programs\Python\Python313\Lib\smtplib.py", line 890, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'recipient_email': (553, b'5.1.3 The recipient address <recipient_email> is not a valid RFC 5321\n5.1.3 address. For more information, go to\n5.1.3 https://support.google.com/a/answer/3221692 and review RFC 5321\n5.1.3 specifications. 2adb3069b0e04-53e38e08361sm2227658e87.23 - gsmtp')}
PS C:\Users\Test\OneDrive\Desktop\патрон>

river fog
#

You appear to have told it to send an email to a fake address.

sharp echo
river fog
#

Oh, then it looks like the email address is malformed in some way.

sharp echo
#

thanks for the work but I was able to solve the problem myself

swift zealotBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.