+ 3
SMTPlib with Python
I have made a script that should send an email with python using smtplib. Here it is: import smtplib msg = "test email" mail = smtplib.SMTP("smtp.gmail.com",578) mail.ehlo() mail.starttls() mail.login("myemail@gmail.com", "mypassword") mail.sendmail("fromemail@gmail.com","toemail@gmail.com",msg) mail.close() NOTE: I have replaced my actual credentials for this code, they are correct, that is not the issue. This is my error: Either nothing happens, and it just sits there, no error showing, not ending the script, or it doesn't accept my username and password.
17 Antworten
+ 7
Yay ;)
+ 4
Usually, the port for SMTP is 587, like Diego suggests. Also, check for spelling mistakes. Eventhough this is just an example login, its domain is gmai.com instead of gmail.com
+ 4
You wrote myemail@gmai.com when it should be myemail@gmail.com
+ 4
Try with the login only, no @gmail.com
+ 4
Oh, one more thing -- gmail has a strict security policy and the default settings of each email account DO NOT allow unauthorized applications to connect *at all*
You have to change your security settings perhaps?
https://support.google.com/accounts/answer/6010255
+ 4
Can you post the code at the code playground? (delete the password first of course :)
I have published my code that works (outside Sololearn) and this part of code is pretty similar. I wonder what might be your problem...
https://code.sololearn.com/c03tR6z8U0NB/?ref=app
+ 3
Ok, got an "unauthorized access" message and a hint to log in via web browser and change the settings. After that, I was able to successfully send an email using your script.
+ 3
So what kind of error are you receiving now?
+ 2
Try using port 587 instead of 578, and call mail.ehlo() again after mail.starttls().
+ 2
Hmmm. That's strange. Now it works.
🤔🤔🤔🤔🤔🤔
+ 1
I found that earlier and already did that, didn't change anything apparently
0
So I should change it to
smtp.gmai.com?
if I do that then it just doesn't do anything, and when I cancel it it got stuck in create connection.
0
Ohhhh....
ok I changed that
it still doesn't work
Username and Password not accepted
0
Same error
0
https://code.sololearn.com/cKXVcVMs2yGi/?ref=app
Here you go:
0
I did that too, look at my feed, put image there
0
Wait, I'll post another picture