我正在使WEB应用程序发送电子邮件。我编写了代码,
def mail(self,mail_adress, docx):
msg = MIMEMultipart()
msg['Subject'] = 'TEST'
msg['From'] = 'info@xxx.com'
msg['To'] = mail_adress
body = "TEST"
body = MIMEText(body)
msg.attach(body)
mine = {'type': 'text', 'subtype': 'docx'}
attachment = MIMEBase(mine['type'], mine['subtype'])
name = os.path.dirname(os.path.abspath(__name__))
attach_file = {'name': 'test.docx', 'path': name + "/" + docx}
file = open(attach_file['path'], 'rb')
attachment.set_payload(file.read())
file.close()
encoders.encode_base64(attachment)
msg.attach(attachment)
attachment.add_header("Content-Disposition", "attachment", filename=attach_file['name'])
server = smtplib.SMTP()
server.connect()
server.ehlo()
server.starttls()
server.ehlo()
server.send_message(msg,mail_adress)
server.quit()
当我运行它时, [Errno 111]发生了连接被拒绝的错误。我真的不明白为什么会发生这样的错误。我该如何解决?