App Engine调用Amazon SES(简单电子邮件服务)时出现“名称或服务未知”错误

有时候-并非总是如此-从Google App Engine / Python 2.7调用Amazon SES时,出现code = (df.col1.str.extractall('(\d+)')[0]+ ' ') \ .sum(level=0).str.strip().rename('code') name = (df.col1.str.extractall('([a-zA-Z]+)')[0]+ ' ') \ .sum(level=0).str.strip().rename('name') df_out = pd.concat([code,name],axis=1) Out[139]: code name 94 520 XX 111 316 aa 114 NaN Entry 144 325 Sport 146 35 xColor d 166 420 M Sport 167 NaN XX 199 NaN XX 225 645 Ai 错误。

我正在调用Amazon的示例代码,我将在此问题的结尾处粘贴该示例代码,但可以在此处找到: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-using-smtp.html

我当然输入了我的Amazon帐户凭证,并使用白名单中的电子邮件地址进行发送,并使用有效地址进行接收。每当我在桌面Python系统上运行该代码时,该代码就可以完美地运行。

这是回溯:

name or service not known

我还没有发现可能导致它在App Engine上失败而不是在其他时候失败的任何事情。这个StackOverflow问题讨论有关为MailGun配置防火墙。

Java Google App Engine won't send email via Mailgun SMTP

我必须打开计费功能来配置防火墙,除非有必要,否则我不想这样做。另外,如果它是防火墙配置错误,为什么有时还能正常工作?

这是Amazon的示例代码,根据我的使用进行了修改。另外,我的SES帐户位于俄勒冈西部2区。

File "/base/data/home/apps/m~/1.4222/emailer_test.py",line 79,in <module>
    server = smtplib.SMTP(HOST,PORT)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/79cf/python27/python27_dist/lib/python2.7/smtplib.py",line 256,in __init__
    (code,msg) = self.connect(host,port)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/79cf/python27/python27_dist/lib/python2.7/smtplib.py",line 316,in connect
    self.sock = self._get_socket(host,port,self.timeout)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/79cf/python27/python27_dist/lib/python2.7/smtplib.py",line 291,in _get_socket
    return socket.create_connection((host,port),timeout)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/79cf/python27/python27_dist/lib/python2.7/socket.py",line 560,in create_connection
    for res in getaddrinfo(host,SOCK_STREAM):
gaierror: [Errno -2] Name or service not known

EDIT :似乎SMTP与AppEngine不兼容: Can Google App Engine use a third party SMTP server?

qq9931 回答:App Engine调用Amazon SES(简单电子邮件服务)时出现“名称或服务未知”错误

正如您提到的,当您尝试通过套接字使用外部SMTP服务时会遇到一些问题。我的建议是使用 Amazon SES API作为替代。

python发送电子邮件的请求语法如下

response = client.send_email(
Source='string',Destination={
    'ToAddresses': [
        'string',],'CcAddresses': [
        'string','BccAddresses': [
        'string',]
},Message={
    'Subject': {
        'Data': 'string','Charset': 'string'
    },'Body': {
        'Text': {
            'Data': 'string','Charset': 'string'
        },'Html': {
            'Data': 'string','Charset': 'string'
        }
    }
},ReplyToAddresses=[
    'string',ReturnPath='string',SourceArn='string',ReturnPathArn='string',Tags=[
    {
        'Name': 'string','Value': 'string'
    },ConfigurationSetName='string'
)

发送简单电子邮件的示例:

import boto3

client = boto3.client(
    'ses',region_name=region,aws_access_key_id='aws_access_key_string',aws_secret_access_key='aws_secret_key_string'
)

    response = client.send_email(
    Destination={
        'ToAddresses': ['recipient1@domain.com','recipient2@domain.com],},Message={
        'Body': {
            'Text': {
                'Charset': 'UTF-8','Data': 'email body string','Subject': {
            'Charset': 'UTF-8','Data': 'email subject string',Source='sender.email@domain.com',)

Here's更多可用于SES API的方法。

本文链接:https://www.f2er.com/3164479.html

大家都在问