при отправке почты с помощью smtplib в python получил ошибку (11004, 'getaddrinfo fail') - PullRequest
0 голосов
/ 20 апреля 2020

Я отправляю почту, используя скрипт python на сервере разработки, у которого нет соединения inte rnet, но я проверяю соединение с SMTP-сервером, проверяя связь с сервером и он подключен. Но я получаю сообщение об ошибке (11004, сбой getaddrinfo) при подключении к нему с помощью smtplib.

Пожалуйста, помогите мне в этом вопросе! Ниже код, который я использую

msg = MIMEMultipart()
msg["From"] = "sender"
msg["To"] = 'recipient'
msg["Subject"] = "Testing Email"
message = 'Hi,\n \nThis is testing mail.'
ctype, encoding = mimetypes.guess_type(file)
if ctype is None or encoding is not None:
   ctype = "application/octet-stream"
maintype, subtype = ctype.split("/", 1)
fp = open(file, "rb")
attachment = MIMEBase(maintype, subtype)
attachment.set_payload(fp.read())
fp.close()
encoders.encode_base64(attachment)
attachment.add_header("Content-Disposition", "attachment", filename='report.xlsx')
msg.attach(MIMEText(message, 'plain'))
msg.attach(attachment)

try:
    server = smtplib.SMTP(server_name)
    server.set_debuglevel(0)
    server.sendmail(sender, receiver, msg.as_string())
    server.quit()
except Exception as e:
    print(e.args)
...