以下のpythonスクリプトを実行してSMTPを使用してpdf添付ファイルを送信すると、SMTPDataError例外が発生しました。私は同じ送信者と同じ受信者に以下のコードを使用してテキストファイルまたは画像ファイルを送信することができます。 pdfファイルのサイズはほとんど1 MBです。SMTPを使用して添付ファイルとしてPDFを送信中にエラーが発生しました
import smtplib
import email
import email.mime
import email.mime.application
from_email = "[email protected]"
from_passwd = ""
to_email = "[email protected]"
message = email.mime.Multipart.MIMEMultipart('mixed')
message['Subject'] = 'Test_run'
message['From'] = from_email
message['To'] = to_email
text_part = email.mime.Text.MIMEText("""This is an e-mail message to be sent in HTML format
<b>This is HTML message.</b>
<h1>This is headline.</h1>
""",'html')
message.attach(text_part)
filename1 = "some_doc.pdf"
fp = open(filename1 , 'rb')
attach_part = email.mime.application.MIMEApplication(fp.read(),"pdf")
fp.close()
attach_part.add_header('Content-Disposition','attachment',filename = "some_doc.pdf")
message.attach(attach_part)
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login(from_email,from_passwd)
server.sendmail(from_email,to_email,message.as_string())
server.close()
エラーメッセージがすべてのヘルプははるかに高く評価されて
File "/usr/lib/python2.7/smtplib.py", line 746, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (550, '5.7.1 The user or domain that you are sending to (or from) has a policy that\n5.7.1 prohibited the mail that you sent. Please contact your domain\n5.7.1 administrator for further details. For more information, please visit\n5.7.1 https://support.google.com/a/answer/172179 66sm37804549pfx.29 - gsmtp')
に遭遇しました。
https://support.google.com/a/answer/172179 – e4c5
はエラーメッセージを読み、その指示に従ったことがありますね? –