Both providers work over IMAP, but they do not accept your normal password.
- Gmail: turn on two-step verification and create an app password for the plugin.
- Microsoft 365: allow IMAP for the mailbox and use an app password or a mailbox that is not blocked by security defaults.
If the scheduled task reports that it cannot authenticate, the password is almost always the cause.