You write a script to use getmail_fetch and submit your password using security(1)
.
For example:
getmail_fetch --ssl $server \ $user \ $(security find-internet-password -g -s $server -a $user 2>&1 1>&- | sed -e 's/password: "\(.*\)"/\1/') \ $destination
You will need to click "Always Allow" the first time you access a particular keychain item with security
.