从swiftmailer yaml配置中获取参数

I need to set up a configuration where a user sets a email-address in a yaml file (swiftmailer.yml) and while sending out emails, this address would be fetched from the container.

I tried using ContainerInterface to fetch the username-field but it returns the following error:

Address in mailbox given [*\id] does not comply with RFC 2822, 3.6.2.

I can't use ContainerBuilder to get definition because it shows No such service exists.

Tried using ContainerBuilder as follows:

$mailer = $this->container->get('swiftmailer.mailer.my_mailer');

$mailerAddress = $this->container->getParameter(
    'swiftmailer.mailer.my_mailer.transport.smtp.username'
);
$message = (new \Swift_Message("Notification Subject"))
    // Set sender's email from a yaml file
    ->setFrom($mailerAddress)
    ->setTo($userEmail)

This $mailerAddress parameter should be fetched from a YAML-file as mentioned before.