I am trying to fetch mail from a email account, I cannot login when I have password with special characters.
import imaplib
username = 'test#test.com'
password = "test!002"
imap_server = 'imap.test.com'
mail = imaplib.IMAP4_SSL(imap_server)
mail.login(username, password)
Output:
[AUTHENTICATIONFAILED] Invalid credentials(Failure)'
Exception in connectionb'[AUTHENTICATIONFAILED] Invalid credentials(Failure)
The same code works if I change the password which does not special Characters.
Can any one tell me how to login to imap with passwords containing special characters.
I'm not sure if this will help you but i have looked at the documentation and found this.
IMAP4.authenticate changed in version 3.5: string usernames and passwords are now encoded to utf-8 instead of being limited to ASCII.
You could try to encode the password, maybe the username also just in case, and retry it?
For more information please read:
IMAP4.authenticate(mechanism, authobject)
Related
I am trying to log in to mail using imaplib for confirmation but it gave me always incorrect. but if I used a less secure password it would work. But I want to use only the original password.
import imaplib
def check_email_login(email, password):
try:
imap = imaplib.IMAP4_SSL("imap.gmail.com", 993)
imap.login(email, password)
imap.logout()
return "Success"
except imaplib.IMAP4.error:
return "Incorrect"
from mailer import Mailer
mail = Mailer(email='my email', password='my password')
mail.send(receiver='random email', subject="test", message="Cool reset")
When I run this I get an error, it says
Error: Email And Password Not Accepted.
Note:
Make sure you Allowed less secure apps,
if you didn't, visit this link:
==> https://myaccount.google.com/lesssecureapps
For More information visit this link:
==> https://support.google.com/mail/?p=BadCredentials
I've already set the "Allow less secure apps" to on.
Btw the email credentials aren't the actual ones I use in my code
The following works for me with my own credentials, you will just want to replace the curly braces with your data (EX: mail = Mailer("email", "password")):
from mailer import Mailer
mail = Mailer("{sender_email}", "{sender_password}")
mail.send(receiver="{receiver_email}", subject="{subject}", message={"message"})
I found this documentation for quick-mailer. Perhaps the issue is the use of single quotes, maybe try using only double quotes?
Take another stab at it with that info, good luck.
I am creating a basic login page using Python Sockets and I am trying to make the Password input blank when the user types, I am using CLIENT.send() to send the "Password: " string and CLIENT.recv(1024) to fetch the given data.
you can use the getpass library like this:
import getpass
password = getpass.getpass()
this will make the password variable get an input, but nothing will come up as you type
I am developing an application with Django. In forms.py, where the classes for my forms are stored, I have written a clean function to verify that all the emails typed into a textbox adhere to the proper format (person#site.com).
In this clean function, I build the email message with an EmailMessage object:
def clean_recipients(self):
rec = self.data['recipients'].split(",")
recList = []
for recipient in rec:
reci = str.strip(str(recipient))
recList.append(reci)
message = (self.data['subject'], self.data['message'], 'hi#world.com', recList)
mail = EmailMessage(self.data['subject'], self.data['message'], 'from#somebody.com', ['email_list#mysite.org'], recList)
try:
mail.send(fail_silently=False)
except Exception:
raise forms.ValidationError('Please check inputted emails for validity.')
return self.data['recipients']
However, the exception 'Please check inputted emails for validity.' is never raised on the form regardless of what I input into the textbox. If I input random characters into the textbox, simply no message is sent.
What is the proper way to catch if the email was not sent properly?
Thank you.
Try to clean recipients emails format only in the clean_recipients. There is snippet how to check email. http://djangosnippets.org/snippets/1093/ . Raise validation error if email format does not match.
Create email and send it from the form's clean method (if you need show sending errors. You will need check for form errors before send.) or from the view.
PS. get your data this way - self.cleaned_data instead of self.data.
I need a python script that prompts for a username and password and tries to login to Hotmail using those credentials, outputting whether they are valid or not.
Hotmail login!
import poplib
M = poplib.POP3_SSL('pop3.live.com', 995) #Connect to hotmail pop3 server
try:
M.user(raw_input("username: ")) #Get the username from the standar input
M.pass_(raw_input("password: ")) #Get the password from the standar input
except:
print "username or password incorrect"
else:
print "Successful login"
Edit: since you only need to know if you can do a login, I rewrite the code
If you lose connection during the typing the username or password, I don't know what will happend.
This is alternative if pop3 failed. just check login using IMAP for hotmail,live or now only outlook.com by using python outlook library you can download here :
https://github.com/awangga/outlook
import outlook
mail = outlook.Outlook()
mail.checkLogin()
it will attemp username and password for authentication validation.