【发布时间】:2021-02-27 20:50:57
【问题描述】:
我编写了一个使用 aws ses 发送电子邮件的系统(代码如下)。这在网站上运行良好,但我也很惊讶它似乎可以在我的本地计算机上运行。我想知道的是,如果我不小心为我的 aws 帐户提供了全球发送电子邮件的能力,或者我的本地电脑是否以某种方式登录到 aws,以便它仍然可以发送电子邮件。如果是这种情况,我该如何注销以确保它是安全的?或者我如何确保它只有网站可以发送电子邮件。
谢谢
标记
# Form is valid, get the data from the form
sender_email = form.cleaned_data['form_email']
# Generate the new email message
strNewSubject = "CONTACT FROM sendemail DJANGO APP"
strNewMessage = f"Hello from a random user of sendemail Django App."
# Create a new SES resource and specify a region. SES is in
# eu-west-1 NOT eu-west-2
client = boto3.client('ses', region_name="eu-west-1")
tmpDestination = {'ToAddresses':
["blah@something.com", ], }
tmpMessage = {
'Body': {
'Text': {
'Charset': "UTF-8",
'Data': strNewMessage,
},
},
'Subject': {
'Charset': "UTF-8",
'Data': strNewSubject,
},
}
# Provide the contents of the email.
response = client.send_email(
Destination=tmpDestination,
Message=tmpMessage,
Source="srcaddress@gmail.com"
)
# Email sent and no error's
return True
【问题讨论】:
-
如果您在某个时候运行
aws configure来配置 awscli 并添加您的访问密钥,那么这就是这里所使用的。如果要从系统中删除所有已配置的访问密钥,可以删除~/.aws目录。
标签: amazon-web-services amazon-ses