Python 使用SMTP将PDF作为附件发送时出错

Python 使用SMTP将PDF作为附件发送时出错,python,pdf,mime,smtplib,Python,Pdf,Mime,Smtplib,运行下面的python脚本以使用SMTP发送pdf附件时,遇到SMTPDataError异常。我能够发送文本或图像文件使用以下代码与相同的发件人和相同的收件人。pdf文件大小几乎不到1MB import smtplib import email import email.mime import email.mime.application from_email = "XXXX@gmail.com" from_passwd = "" to_email = "abc@gmail.com" mes

运行下面的python脚本以使用SMTP发送pdf附件时,遇到SMTPDataError异常。我能够发送文本或图像文件使用以下代码与相同的发件人和相同的收件人。pdf文件大小几乎不到1MB

import smtplib
import email
import email.mime
import email.mime.application

from_email = "XXXX@gmail.com"
from_passwd = ""
to_email = "abc@gmail.com"

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()  

非常感谢您的帮助。

您是否尝试过向不同域中的其他收件人发送PDF?或者向同一个收件人发送大小相似的图像


听起来此域可能不允许使用pdf附件,无论出于何种原因…

您是否尝试将pdf发送到其他域中的其他收件人?或者向同一个收件人发送大小相似的图像


听起来此域可能不允许pdf附件,无论出于何种原因…

您是否尝试阅读错误消息并遵循其说明?您是否尝试阅读错误消息并遵循其说明?我可以向同一收件人发送更大尺寸的图像。对于其他收件人,未遇到任何异常,但在我发送的邮件中收到“邮件未送达”。是否要配置任何帐户设置?我可以向同一收件人发送更大尺寸的图像。对于其他收件人,未遇到任何异常,但在我发送的邮件中收到“邮件未送达”。是否要配置任何帐户设置??
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')