Based on my research, many mail servers do not allow you to do this for security reasons. You typically wouldn't want an email address to be able to impersonate others, as that could lead to all types of mischief and misunderstandings.
Therefore, I believe you need to store the credentials of each user for which you'll be sending emails.
I do not know the imap module as I always use the email with template module. And I think Eric's answer is wrong at least for the Mendix mail server. You should be able to change the FROM address because you should be able to send mails from an adress like email@example.com. The Mendix mail server will allow that in the cloud. So it depends which mail server you are using. Indeed like Erix says most public mail servers will not allow it.