나는 이상한 버그가 있습니다. smtplib을 사용하여 Gmail 계정에서 이메일을 보내고 있습니다. 스크립트를 실행할 때마다 보내는 데 사용하고있는 Gmail 계정의 "보낸 사람"탭에 메시지가 표시됩니다. 그러나 때로는 수신 측에서 메시지를받지 못합니다.gmail을 사용하는 python smtplib : 약 35 자 이상의 본문이있는 메시지는 수신되지 않습니다.
나는 메시지 본문의 길이와 그것이 수신되는지 여부 사이의 상관 관계에 주목했습니다. "foo"라는 메시지는 매번 전달되고 원하는 메시지는 약 200 자 길이되지 않습니다. 나는 몸 길이가 0에서 60 사이 인 메시지를 보내려고 노력했다. 두 번 모두 60 개의 쇼를 보내는 gmail 계정의 '보낸'폴더에 표시했지만 수신 전자 메일 계정에는 다음과 같이 표시된다.
메일 기능 여기
for i in range(100):
mail('[email protected]','testing limit',str(i) + "a"*i)
그리고있다 :
def mail(to, subject, text, attach=None):
"""Sends an email, formatted as HTML to list of senders with an optional attachment.
Specifically, the 'to' argument must be a comma seperated list of email addresses.
'subject' and 'text' are what appear in the email subject and body, respectively and
'attach' is a path to an attachment.
"""
msg = MIMEMultipart()
# build the email header
msg['From'] = 'A Concerned Robot'
msg['To'] = to
msg['Subject'] = subject
# attach our body text as html
msg.attach(MIMEText(text,'html'))
# attach the attachment if its there
part = MIMEBase('application', 'octet-stream')
if attach is not None:
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
# open up a line with the server
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
# login, send email, logout
mailServer.login(conf.user, conf.pw)
mailServer.sendmail(conf.user, to, msg.as_string())
mailServer.close()
나는 이것이 이상한 버그라고 말해야 만합니다. 나는 지난 며칠 동안 smtplib 모듈을 사용해 왔지만 결코이 문제에 부딪치지 않았다 ... 그러나 나는 당신이 생각해내는 결과와 함께 당신의 예제를 실행했다. 첨부 파일을 스트라이프 처리하고 일반 텍스트를 모두 전송하는 것과 같은 몇 가지 작업을 시도했습니다. +1 이상하고 자극적 인 버그. –
사이드 노트 : 무료 Google 계정을 사용 중이라면 24 시간 동안 500 개의 이메일로 제한됩니다.따라서 테스트 할 때 보낼 메시지 수를 줄이려고 할 수 있습니다. –