How do I send myself an email using Python? - python

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.

Related

What's solution for sending emails from python while gmail " the less secure apps " is not enabled anymore

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

Gmail login error with the help of imaplib in Python

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

How to open SalesForce using the JWT method?

I have written a python script to make updates to SalesForce. However the issue is that I login to SalesForce using my username and password but this is a problem because my password changes regularly. I realize that I need to use the JWT method to avoid this. According to PyPi all I need to do is use simple salesforce and provide a private key and consumer key but I cannot figure out how to do this. I have made a connected app and associated it with a self signed certificate. Please advise on how I finish setting up this method.
You could have a dedicated user account for this with Profile flag that says password never expires. There would be a license cost, yes - but it'd work OK even if you leave company and the updates done by "Mr Admin" can look better to end users than by "Brian". Do you get any "why have you changed my data!!!" angry emails? ;)
But if you really need the JWT route these should help:
https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5
https://gist.github.com/booleangate/30d345ecf0617db0ea19c54c7a44d06f (Python example but read the comments, I had to pip install pyjwt, not jwt)
https://salesforce.stackexchange.com/questions/201636/authentication-using-jwt/201648 (Apex example, 2 versions of code, raw HTTP requests or using built-in JWT libraries)

imaplib not working with some outlook365 accounts

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.

Gmail SMTPAuthenticationError when I attempt to send email via django

I'm using django-registration-redux and the forget password reset dialogue is working on my machine but it fails on the server. I get an SMTPAuthenticationError even though the local server is sending mails just fine. What could I be doing wrong?
This is the error I get:
(534, '5.7.14
<https://accounts.google.com/ContinueSignInsarp=1&scc=1&plt=AKgnsbtwe\n5.7.14 Dz3CKtLMnsuR5AJAalqHTpUCJLECZAJKqbimLhjZ3dzjnEOfMck4BnpTZdlLbVRnkocGVe\n5.7.14 ghl_iEoinCscpmC_RWk8CxJ8MP61MyYKtKljt8gnet-NUj53mRP5ohGJsok8V1z1SWXzGa\n5.7.14 MrBjYMYDHU9MbPFopv5jWzFDQS_4Jop03AACxQAcSD1jGG1uQqFXjULQ2RE-wMPrCcyDKW\n5.7.14 Vq08guBEY2LqcSBp9L3jauD-a9i4>
Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 ra1sm18942520pab.24 - gsmtp')
If you have activated two-step verification, you need to turn that off. Also ,you can try another thing. Go to https://www.google.com/settings/security/lesssecureapps and https://myaccount.google.com/security?pli=1#connectedapps, allow access for the less secure app. Google might consider your server's sign-in process as less secure sign-in technology, which makes your account more vulnerable. So allowing access might help you.
It is because Google blocks sign-in attempts from apps that do not use modern security standards (mentioned on their support page). You can, however, turn on/off this safety feature by going to the link below:
Go to this link and select Turn On
https://www.google.com/settings/security/lesssecureapps
Moreover, google blocks your IP when you try to send an email since its an unusual location, so, you can unblock in the next link
https://support.google.com/accounts/answer/6009563
and clicked in
https://accounts.google.com/b/0/DisplayUnlockCaptcha
More info…smtp mail

Categories