[英]AWS SendRawEmail operation: Illegal address error from multiple recipients
I have an AWS Lambda that uses SES for sending emails.我有一个使用 SES 发送电子邮件的 AWS Lambda。 This function works when I have only one recipient.
当我只有一个收件人时,这个 function 有效。 But as soon as I add 2 or more recipients to the array, it fails with the following error.
但是,一旦我将 2 个或更多收件人添加到数组中,它就会失败并出现以下错误。
I am in a Sandbox environment and saw that I had to verify the email domains that I am sending to.我在沙盒环境中,看到我必须验证我发送到的 email 域。 So that is no longer an issue.
所以这不再是问题。
"An error occurred (InvalidParameterValue) when calling the SendRawEmail operation: Illegal address"
My function is as follows below:我的function如下:
def send_email(sender, recipients, aws_region, subject,url):
client = boto3.client('ses', region_name=aws_region)
BODY_TEXT = "Hi"
BODY_HTML = """\
<H1>Your Results have been process</h1>
<br>
{!s}
</br>
""".format(url)
msg = MIMEMultipart('mixed')
msg['From'] = sender
msg['To'] = ", ".join(recipients)
msg['Subject'] = 'TOI Order Alert'
# The character encoding for the email.
CHARSET = "UTF-8"
msg_body = MIMEMultipart('alternative')
textpart = MIMEText(BODY_TEXT.encode(CHARSET), 'plain', CHARSET)
htmlpart = MIMEText(BODY_HTML.encode(CHARSET), 'html', CHARSET)
# Add the text and HTML parts to the child container.
msg_body.attach(textpart)
msg_body.attach(htmlpart)
# Attach the multipart/alternative child container to the multipart/mixed
# parent container.
msg.attach(msg_body)
# Add the attachment to the parent container.
# msg.attach(att)
# Provide the contents of the email.
response = client.send_raw_email(
Source=msg['From'],
Destinations=[
msg['To']
],
RawMessage={
'Data':msg.as_string(),
}
)
return("Email sent! Message ID:", response['MessageId'])
Here is the script of code the calls this function:这是调用此 function 的代码脚本:
# Send an email with the processed results
sender = 'matt@test.awsapps.com'
recipients = ['matt@gmail.com', 'talha@gmail.com']
aws_region = os.environ["AWS_REGION"]
subject='Testing Emails'
URL = 'Google.com'
response = mail.send_email(sender,recipients,aws_region,subject,url)
Passing recipients as shown below worked for me.如下所示传递收件人对我有用。 You can try the same in your code:
您可以在代码中尝试相同的操作:
response = client.send_raw_email(
Source=msg['From'],
Destinations= recipients ,
RawMessage={
'Data':msg.as_string(),
}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.