PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label smtplib. Show all posts
Showing posts with label smtplib. Show all posts

Tuesday, November 8, 2022

[FIXED] What does this error message mean in Python?

 November 08, 2022     email, gmail, python, python-3.x, smtplib     No comments   

Issue

I made an email spam bot a while ago for fun. (Just as a test and to mess with friends) I tried to run it today and it wouldn't work. Any ideas why and how to fix? I've made sure that this API has access to my email.

Edit: Error Message is Traceback (most recent call last): File "C:\Users\user\OneDrive\Desktop\Code\Spam Bot.py", line 10, in server.login('email', 'password') File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 750, in login raise last_exception File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 739, in login (code, resp) = self.auth( File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 662, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials r185-20020acadac2000000b0035173c2fddasm754089oig.51 - gsmtp')


e = 0

server = smtplib.SMTP('smtp.gmail.com', 587)

server.starttls()

server.login('email', 'password')
while(e < 2):
    server.sendmail('email',
                'receiver',
                'text'
                )
    e = e + 1
    print("DONE")```

Solution

Username and Password not accepted.

Do to the removal of less secure apps you can not use the gmail users actual password when connecting to the smtp server.

You must either enable 2fa on the account and configure an apps password, or switch to using Xoauth2.



Answered By - DaImTo
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, October 23, 2022

[FIXED] How to read email using python and smtplib

 October 23, 2022     email, python, smtp, smtplib, yandex     No comments   

Issue

Found a lot of examples how to send mail, but how can I read inbox? For example yandex.

import smtplib as smtp

email = "me@example.com"
password = "password"

server = smtp.SMTP_SSL('smtp.yandex.com')
server.set_debuglevel(1)
server.ehlo(email)
server.login(email, password)
server.auth_plain()
# server.get_and_print_your_inbox_magic_method()
server.quit()

Solution

The SMTP protocol is for sending mails. If you want to look at your inbox - aka receive mails - you need to use POP3 or IMAP.

But just like smtplib, Python also has imaplib for IMAP and poplib for POP3.



Answered By - finefoot
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 11, 2022

[FIXED] When using smtplib and Gmail's SMTP in Python to send emails, why can you not change the sender address?

 July 11, 2022     email, message, python, smtp, smtplib     No comments   

Issue

I am currently trying to send emails via smtplib with the following code:

import smtplib
import email.utils
from email.mime.text import MIMEText

smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login('username@gmail.com', 'pwd')
msg['Subject'] = "subject line"
msg['From'] = 'newusername@gmail.com'
msg['To'] = 'friend@gmail.com'
smtpserver.sendmail(sender, recipients, msg.as_string())

When I do something like this, instead of the recipient getting an email from newusername@gmail.com, they get it from username@gmail.com, which was the email I used for authentication.

Is there a way to change this?


Solution

This is an intentional security feature in gmail, and other public mail servers, called SMTP AUTH.

Without this feature, anyone with a gmail address could send mail impersonating anyone else with a gmail address. I could send a message claiming to be from you, and the recipient would have no way of knowing it wasn't from you, and you'd have no way to prove it wasn't from you.

But it wouldn't matter anyway, because spammers would be sending so much more email with your address than you do that email addresses would be effectively meaningless, and the whole email system would fall apart. Which is what almost happened in the late 90s. Only a concerted campaign to require SMTP AUTH on all open submission servers, including blacklisting all mail from servers that didn't comply (even the ones that used POP-before-SMTP, IMAP-before-SMTP, IP/MAC verification, or other alternatives to SMTP AUTH) managed to keep the spammers from ruining everything.

Later, another security/anti-spam measure, called DKIM, was added, which gmail also uses: most servers will throw out any messages that isn't signed by the originating server, indicating that the server trusts that the message came from who it says it came from. Obviously, gmail isn't going to certify that a message came from newusername when it actually came from username.1 And, if they did, people who administer other servers would just blacklist gmail signatures are meaningless.


1. Unless they have some reason to trust that username has the right to send mail as newusername—corporate mail servers sometimes do have a feature like that, allowing you to configure things so, e.g., a secretary can send mail from his boss's address without having his boss's password.



Answered By - abarnert
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing