I am trying to send emails through SES using boto3. Below is my code.
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import boto3
message = MIMEMultipart()
message['Subject'] = 'i am subject äöü'
message['From'] = 'sender äöü <[email protected]>'
message['To'] = 'receipient äöü <[email protected]>'
html = MIMEText('<strong>Welcome to AWS SES äöü</strong>', 'html')
message.attach(html)
ses.send_raw_email(
RawMessage={
'Data': message.as_string()
}
)
But i am getting the exception below. This error is something to do with unicode characters(äöü) in From
and To
addresses. If i remove the unicode characters then email is sent successfully.
An error occurred (InvalidParameterValue) when calling the SendRawEmail operation: Missing final '@domain'
Please help to resolve the issue.
Encode the email parts as suggested in https://mg.pov.lt/blog/unicode-emails-in-python.html. This solved the issue and now i am able to send emails.