'554, b'Transaction failed: Nested group in sending email using Amazon Aws SES

I want to send email from my Ubuntu server thru Amazon AWS SES. I've a working code and it's able to send an email.

However when I wrap the working code within a function it's giving this error:

Something with SMTP went wrong...
(554, b'Transaction failed: Nested group')

I'm attaching visual code comparison, .. I'm curious as to what could be wrong.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source