Using external SMTP extensions and letting users use custom SMTP

I have an app where I want my user to be able to add their own SMTP server, whether by Mailgun, Amazon SES, etc.

If we’re taking the mailgun as an example, right now my Mailgun is set up in config/web.php like so


'mailgun' => [

				

			   'class' => 'boundstate\mailgun\Mailer',

			           'key' => 'MYKEY',

			           'domain' => 'DOMAIN',

					  

			    ],

Then I use the following to compose an email


Yii::$app->mailgun->compose()->setFrom([$FROM])

									->setReplyTo($contest_creator_email)

								    ->setTo($email)

								    ->setSubject($subject_line)

								    ->setTextBody($plaintext)

								    ->setHtmlBody($htmlemail)

								    ->send();

					

How would I make it so that my user could set-up his own key instead of mine? Is there a way to do this?