smtplib.SMTPSenderRefused:(452,' 4.3.1系统资源不足'

时间:2017-04-24 10:47:48

标签: python linux smtp sendmail

我每小时都会在rhel 7.3上安排Python脚本,将邮件发送到我的邮件ID,并在邮件中打印html表格(html文件大小约为KB)

所有工作都好几天但是,

我突然停止接收电子邮件,我尝试手动运行脚本, 它抛出以下错误

********错误********

[root@root alerts]# python hour_report.py
Traceback (most recent call last):
  File "hour_report.py", line 49, in <module>
    s.sendmail(me, recipients, msg.as_string())
  File "/usr/lib64/python2.7/smtplib.py", line 735, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (452, '4.3.1 Insufficient system resources', 'domain@domain.com')

我尝试更新此常用解决方案

postconf -e "message_size_limit = 30720000"  

但是没有解决问题,我是这个smtp邮件的新手 请帮帮我...... !!

*********脚本*********

#!/usr/bin/env python

import smtplib
import os
import os.path
import sys
import datetime

mylist = []
today = datetime.date.today()
mylist.append(today)
PATH='/home/opsol/alerts/Hourly_report.html'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText

 # me == my email address
 # you == recipient's email address
 me = "domain@domain.com"
 you = "my@domain.com"
 recipients = ['my@domain.com']
 # Create message container - the correct MIME type is multipart/alternative.
 msg = MIMEMultipart('alternative')
 msg['Subject'] = "My hour Report " + str(mylist[0])
 msg['From'] = me
 msg['To'] = ", ".join(recipients)
 # Create the body of the message (a plain-text and an HTML version).
 text = "Hi!"
 filename = PATH
 html = ""
 with open(filename, "r") as f:
  html = f.read()
 # Record the MIME types of both parts - text/plain and text/html.
 part1 = MIMEText(html, 'html')
 part2 = MIMEText(html, 'html')

 # Attach parts into message container.
 # According to RFC 2046, the last part of a multipart message, in this case
 # the HTML message, is best and preferred.
 msg.attach(part1)
 msg.attach(part2)

 # Send the message via local SMTP server.
 s = smtplib.SMTP('X.X.X.X')
 # sendmail function takes 3 arguments: sender's address, recipient's address
 # and message to send - here it is sent as one string.
 s.sendmail(me, recipients, msg.as_string())
 s.quit()
 os.remove(PATH)

0 个答案:

没有答案