'connecting to special email with python (3 credentials needed and not 2)

I want to connect to my university email from python- sending and receiving messages. The emails server is a gmail server, but when connecting manually I need to enter my email, ID number and password. Its the regular university identification- but that's the only way for getting into the email. Here is part of what I tried:

import imaplib
import email
from email.header import decode_header
import webbrowser
import os

username = ""
password = ""
ID=""
imap = imaplib.IMAP4_SSL("imap.gmail.com")
imap.login(username,ID, password)
# ...

I get this error for the last line:

TypeError: login() takes 3 positional arguments but 4 were given

I know that login() should take 2 parameters, but I didn't find any other solution for connecting. I tried with smtplib and got the same error. My questions is, how can I connect to my email, when 3 credentials are needed and not the regular 2?

thanks :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source