简体   繁体   English

AWS SendRawEmail 操作:来自多个收件人的非法地址错误

[英]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.

相关问题 AWS SES(简单电子邮件服务)记录发送的电子邮件收件人地址 - AWS SES(Simple Email Service) logging sent email recipients address 使用 SendGrid 从逻辑应用向多个收件人发送电子邮件 - Sending emails with SendGrid from a logic app to multiple recipients 如何从发送网格获取发送给多个收件人的单个 email 的 email 活动状态 - How to get the email activity status from send grid for a single email sent to multiple recipients aws批处理上的非法指令 - illegal instruction on aws batch AWS 错误消息:当前正在针对此资源执行冲突的条件操作 - AWS Error Message: A conflicting conditional operation is currently in progress against this resource 如何在 `Node aws-sdk` sendRawEmail 函数中发送 PDF 附件? - How can send PDF attachment in `Node aws-sdk` sendRawEmail function? 禁止向多个收件人发送 email - Get forbidden to send email with multiple recipients 如何使用 MultiProcessing、mp.Manager() 运行多个 AWS Batch 作业,而不会出现端口地址冲突错误地址已在使用中? - How do you run multiple AWS Batch jobs with MultiProcessing, mp.Manager(), without conflicting port addresses error Address already in use? 使用 docker-compose 时,EISDIR: illegal operation on a directory, read - When using docker-compose, EISDIR: illegal operation on a directory, read AWS Lambda:调用 GetObject 操作时发生错误 (NoSuchKey):指定的键不存在 - AWS Lambda: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM