如何通过 AWS SES 向多个收件人发送电子邮件
How to send email to multiple recipients through AWS SES
大家好,我正在尝试使用 Python 通过 AWS SES 向多个用户发送电子邮件,但每当我尝试发送邮件时,我都会收到错误消息:非法地址
这是我的代码:
def emailServiceForCustomerInformation(self, emailSubject, customerLicenseMessage, installation_name):
# logger = ToolsLogger.getOrCreateLogger(current_user.keyspace)
logger = ToolsLogger.getOrCreateRootLogger()
logger.info("Email service For Customer is started")
record = int(recordCount)
# print("emailRcord-",record)
# This address must be verified with Amazon SES.
SENDER = "Snehil singh<snehil@codedata.io>"
# is still in the sandbox, this address must be verified.
recipients = ["cosmoandysysmo@gmail.com","snehil@codedata.io"]
RECIPIENT = ", ".join(recipients)
# If necessary, replace us-east-1 with the AWS Region currently using for Amazon SES.
AWS_REGION = "us-east-1"
# The subject line for the email.
SUBJECT = emailSubject
BODY_TEXT = (customerLicenseMessage + ' ''For InstallationName-'+ installation_name)
# The character encoding for the email.
CHARSET = "UTF-8"
client = boto3.client('ses', region_name=AWS_REGION,
aws_access_key_id=config[os.environ['CONFIG_TYPE']].S3_ACCESS_KEY,
aws_secret_access_key=config[os.environ['CONFIG_TYPE']].S3_ACCESS_SECRET_KEY,
config=Config(signature_version='s3v4'))
is_success = True
# Try to send the email.
try:
# Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
# If you are not using a configuration set, comment or delete the
# following line
# ConfigurationSetName=CONFIGURATION_SET,
)
# Display an error if something goes wrong.
except ClientError as e:
logger.exception(e)
print(e.response['Error']['Message'])
is_success = False
else:
# print("Email sent! Message ID:"),
# print(response['MessageId'])
logger.info("Email service is Completed and send to the mail")
return is_success
我在互联网上搜索过,但没有一个答案有帮助这是我尝试过的另一种方法https://www.jeffgeerling.com/blogs/jeff-geerling/sending-emails-multiple但这也没有帮助请帮助我哪里做错了我在哪里修改它请ping我如果您对此有任何疑问...提前致谢。
在boto3 SES send_email documentation中:
response = client.send_email(
Source='string',
Destination={
'ToAddresses': [
'string',
],
'CcAddresses': [
'string',
],
'BccAddresses': [
'string',
]
},
如果您阅读 SES SendEmail API call documentation, it tells you that the Destination object 是:
BccAddresses.member.N
The BCC: field(s) of the message.
Type: Array of strings
Required: No
CcAddresses.member.N
The CC: field(s) of the message.
Type: Array of strings
Required: No
ToAddresses.member.N
The To: field(s) of the message.
Type: Array of strings
Required: No
总结:不要加入地址构造RECIPIENT。 RECIPIENT 需要是一个字符串数组(一个列表,在 Python 中),其中每个字符串是一个电子邮件地址。
在我看来,您应该传递 'recipient',而不是 RECIPENT 字符串。尝试这样的事情:
Destination={'ToAddresses':recipients}
它似乎需要一个数组,而不是逗号分隔的字符串列表。
RECIPIENT 必须是字符串数组 > ['email1', 'email2']
和>>
Destination={
'ToAddresses': [
RECIPIENT,
],
},
至
Destination={
'ToAddresses': RECIPIENT
},
大家好,我正在尝试使用 Python 通过 AWS SES 向多个用户发送电子邮件,但每当我尝试发送邮件时,我都会收到错误消息:非法地址
这是我的代码:
def emailServiceForCustomerInformation(self, emailSubject, customerLicenseMessage, installation_name):
# logger = ToolsLogger.getOrCreateLogger(current_user.keyspace)
logger = ToolsLogger.getOrCreateRootLogger()
logger.info("Email service For Customer is started")
record = int(recordCount)
# print("emailRcord-",record)
# This address must be verified with Amazon SES.
SENDER = "Snehil singh<snehil@codedata.io>"
# is still in the sandbox, this address must be verified.
recipients = ["cosmoandysysmo@gmail.com","snehil@codedata.io"]
RECIPIENT = ", ".join(recipients)
# If necessary, replace us-east-1 with the AWS Region currently using for Amazon SES.
AWS_REGION = "us-east-1"
# The subject line for the email.
SUBJECT = emailSubject
BODY_TEXT = (customerLicenseMessage + ' ''For InstallationName-'+ installation_name)
# The character encoding for the email.
CHARSET = "UTF-8"
client = boto3.client('ses', region_name=AWS_REGION,
aws_access_key_id=config[os.environ['CONFIG_TYPE']].S3_ACCESS_KEY,
aws_secret_access_key=config[os.environ['CONFIG_TYPE']].S3_ACCESS_SECRET_KEY,
config=Config(signature_version='s3v4'))
is_success = True
# Try to send the email.
try:
# Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
# If you are not using a configuration set, comment or delete the
# following line
# ConfigurationSetName=CONFIGURATION_SET,
)
# Display an error if something goes wrong.
except ClientError as e:
logger.exception(e)
print(e.response['Error']['Message'])
is_success = False
else:
# print("Email sent! Message ID:"),
# print(response['MessageId'])
logger.info("Email service is Completed and send to the mail")
return is_success
我在互联网上搜索过,但没有一个答案有帮助这是我尝试过的另一种方法https://www.jeffgeerling.com/blogs/jeff-geerling/sending-emails-multiple但这也没有帮助请帮助我哪里做错了我在哪里修改它请ping我如果您对此有任何疑问...提前致谢。
在boto3 SES send_email documentation中:
response = client.send_email(
Source='string',
Destination={
'ToAddresses': [
'string',
],
'CcAddresses': [
'string',
],
'BccAddresses': [
'string',
]
},
如果您阅读 SES SendEmail API call documentation, it tells you that the Destination object 是:
BccAddresses.member.N
The BCC: field(s) of the message.
Type: Array of strings
Required: No
CcAddresses.member.N
The CC: field(s) of the message.
Type: Array of strings
Required: No
ToAddresses.member.N
The To: field(s) of the message.
Type: Array of strings
Required: No
总结:不要加入地址构造RECIPIENT。 RECIPIENT 需要是一个字符串数组(一个列表,在 Python 中),其中每个字符串是一个电子邮件地址。
在我看来,您应该传递 'recipient',而不是 RECIPENT 字符串。尝试这样的事情:
Destination={'ToAddresses':recipients}
它似乎需要一个数组,而不是逗号分隔的字符串列表。
RECIPIENT 必须是字符串数组 > ['email1', 'email2']
和>>
Destination={
'ToAddresses': [
RECIPIENT,
],
},
至
Destination={
'ToAddresses': RECIPIENT
},