I am trying to connect to an email account with the imaplib python module but it doesn't work. With #outlook it works fine for me, but with #mydomain it doesn't work.
It's not a credential issue because I tried a POP connection and it worked, but not with imap.
I have searched in many places and it happens to many but I do not see a solution. Someone who can help me?
There's a few things to look at.
First, make sure IMAP access is enabled in the settings of whatever service you're using.
(Eg, Gmail: Settings > Forwarding and POP/IMAP > Enable IMAP). This is often not enough to fix the issue though, you need to set up an app password.
(Eg, Google: https://myaccount.google.com/security > Enable 2-step verification if it is off > App passwords).
An app password lets you sign into a service using a generated password in lieu of your main account password. Use this app password in your credentials while logging in with imaplib, and it should work. I'd suggest considering using a Microsoft app password too when using imaplib for Outlook, as it's more secure. You aren't storing your actual MS password in plain-text anywhere.
Hope that helps.
Related
I know this has been answered before, but recently gmail updated the "Less secure apps" ToS or something. So with this update, is there a way to do this? (Sorry for short explanation + old duplicates)
Tried this tutorial and when trying to connect to my google acc, less secure apps option disabled
UPDATE: I'll be using chrome notifications, which is useful for what I'm doing. Thanks for trying to help! :D
You can or should be able to use the same code that you are using now. The easest solution would be to enable 2fa on your google account and create an apps password. Quick fix for SMTP username and password not accepted error
Once you have created the apps password you can use that in place of your standard gmail password in your code.
If that doesn't work you can switch to using Xoauth2 and authorize a user and send an access token instead. This method would probably require changes you your existing code.
I recently was using smtp library for sending emails from gmail account but recently it stopped working after research I found out the google can not let you enable the less secure app anymore . So is there any workaround this ?
If you want to continue using Gmail SMTP, you can set it up by setting an app password. An app password works like an alternate password for your account. It can only be used by the applications you share it with, so it’s more secure than sharing your primary password.
Here's how you can set it up: https://support.google.com/accounts/answer/185833?hl=en
I am trying to use imaplib in order to fetch my mails
import imaplib
mail= imaplib.IMAP4_SSL("imap.gmail.com")
mail.login("mymailaddress","mypassword")
mail.select("inbox")
but unfortunately, I am getting the following error
File , line 3, in <module>
mail.login("mymailaddress","mypassword")
raise self.error(dat[-1])
imaplib.error: b'[ALERT] Application-specific password required: https://support.google.com/accounts/answer/185833 (Failure)'
I have checked all other suggestion given on similar question but none are working (similar problem). I even enabled IMAP on my account. I also allow less secure app. What might be the reason for this error?
As stated in the error message you are getting You need to go to Sign in with App Passwords
The issue you are having is that you are using the users password. You should be using an apps password
Side note: Update as of May 30, 2022
To help keep your account secure, starting May 30, 2022, Google will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.
This means anyone connecting to the smtp / imap server and using the users password will get an error. Less secure apps will no work anymore.
You need to switch to using xoauth2 or trying an apps password. At this time it is not clear if apps password will work or not.
At this time it is not clear if apps password will work or not.
I was able to set up apps password today following an article in the google help center
I am using my mail server to send mail using Django. When I try to use the send_mail function, I am met with an authentication error. I know that it is not the password, because I can use it to login to my mail account.
How My Mail Server is Setup
I am running Ubuntu 16.0.4 with Nginx and Gunicorn for my Django application. I have installed Roundcube, postfix and dovecot.
How Do I add Users to Roundcube?
For me, the only way I know how to do this is by just adding a new user from the CLI using adduser <user> and from there, logging into Roundcube so that my new user is added to the Roundcube database, and I have an accessible account on Roundcube.
What I Suspect to be The Issue
Since I am creating the users for Roundcube directly from the CLI and they are full Unix users, I can only login to Roundcube using their actual username, and not username#domain.tld. I suspect that Django is trying to authenticate with user#domain.tld rather than user and that is what is causing the issue.
How Can I Fix This?
I am not sure, hence why I am here. I have done my research and cannot find the proper information on making it so that I can login to Roundcube using user#domain.tld instead of just user, but I don't think this will solve my issue.
I have also done research and cannot find an answer on how to create just a mail user, and not a full-blown Unix user. I was thinking this might be my best option. Although, I could be completely wrong.
I'm following along with this book and in chapter 18 part of the current assignment involves sending an email via Django. I have a yearly domain I use for testing, and rather than pay an additional 5$ a month I figured I'd just have the emails forwarded to an existing address, using these instructions.
I then went ahead and set it up so I could send mail using an alias via the Sending mail from your forwarded email address section
However, I'm unable to get it working using the generated app password + alias. When I try to send an email from the page it only works if 2FA is disabled and I use my actual gmail credentials, say for example:
EMAIL_HOST_USER = 'bob#gmail.com'
EMAIL_HOST_PASSWORD = 'bobswife123'
It works as intended. However, lets say I wanted to use my generated app password and alias, something like:
EMAIL_HOST_USER = 'alias#bob.com'
EMAIL_HOST_PASSWORD = 'bobsmistress123'
Then I'll get the following error:
Was not able to make any use of the support article from the URL in the above screenshot, but here it is for the sake of convenience:
https://support.google.com/mail/?p=BadCredentials
Anyways, these are the exact steps I'm taking:
From terminal on macOS 10.13.1, I run python manage.py runserver from terminal, and then enter http://localhost:8000/ into Google Chrome. The page displays correctly. I hit enter and try to send the email. Next, it either works, or I get the screenshot shown above. Here's a dpaste of the traceback:
http://dpaste.com/2DVFSPK
other potentially relevant settings:
EMAIL_HOST = 'smtp.gmail.com
EMAIL_PORT = 465
EMAIL_USE_SSL = True
Any help is greatly appreciated!
Regarding the duplication accusation:
I have already tried the accepted answer's instructions from the potential duplicate. Once again, I can get this to work by using my normal Gmail credentials -- but I don't want to reveal my personal email address, which is why I setup an alias using these instructions. This should allow me to send emails on behalf of the alias domain (which I own)
Edit: Adding my response to user inquiring whether I tried the troubleshooting steps (tl;dr yes i did):
Update your email client to the latest version.
Not using an email client for this; not applicable
Use an App Password: If you use 2-Step Verification, try signing in with an App Password.
Already addressed this above; kinda what my issue is about
Allow less secure apps: If you don't use 2-Step Verification, you might need to allow less secure apps to access your account.
Allow less secure apps is already enabled. Doesn't work otherwise
If you recently changed your Gmail password, you might need to re-enter your Gmail account information or completely repeat your Gmail account setup on your other email client.
Not related to my gmail password -- it works when I use my actual gmail credentials and I'm able to login to gmail
If the tips above didn't help, visit https://www.google.com/accounts/DisplayUnlockCaptcha and follow the steps on the page.
Already tried this
The email client's sign-in method might be insecure. Try signing in directly on the Gmail app.
Don't think I can use the gmail app in combination with this; not applicable
I encountered the same issue: I got it working by using different email addresses for login and sendmail (i.e. Login with gmail account and app password,then specify the forwarded email as sender in sendmail).
For example:
smtpObj.login('bob#gmail.com', 'bobsmistress123')
smtpObj.sendmail('alias#bob.com', receiver, emailString)