anatoly1712
Фев. 6, 2015 08:49:10
Python 3.4.2 documentation
19.1.14 email: Example
outer = MIMEMultipart()
outer = ‘Contents of directory %s’ % os.path.abspath(directory)
outer = COMMASPACE.join(args.recipients)
outer = args.sender
outer.preamble = ‘You will not see this in a MIME-aware mail reader.\n’
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
if not os.path.isfile(path):
continue
# Guess the content type based on the file's extension. Encoding
# will be ignored, although we should check for simple things like
# gzip'd or compressed files.
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
# No guess could be made, or the file is encoded (compressed), so
# use a generic bag-of-bits type.
ctype = ‘application/octet-stream’
maintype, subtype = ctype.split('/', 1)
if maintype == ‘text’:
with open(path) as fp:
# Note: we should handle calculating the charset
msg = MIMEText(fp.read(), _subtype=subtype)
elif maintype == ‘image’:
with open(path, ‘rb’) as fp:
msg = MIMEImage(fp.read(), _subtype=subtype)
elif maintype == ‘audio’:
with open(path, ‘rb’) as fp:
msg = MIMEAudio(fp.read(), _subtype=subtype)
else:
with open(path, ‘rb’) as fp:
msg = MIMEBase(maintype, subtype)
msg.set_payload(fp.read())
# Encode the payload using Base64
encoders.encode_base64(msg)
# Set the filename parameter
msg.add_header('Content-Disposition', ‘attachment’, filename=filename)
outer.attach(msg)
py.user.next
Фев. 7, 2015 01:41:34
python.org. email-examplesПример 4.
Всё работает нормально. Присоединил тар с входными данными и выходными данными.
anatoly1712
Фев. 8, 2015 18:17:32
да, все хорошо.
отправляю через “smtp.mail.ru”
как сохранить письмо в папке ОТПРАВЛЕННЫЕ
py.user.next
Фев. 9, 2015 04:47:28
anatoly1712
как сохранить письмо в папке ОТПРАВЛЕННЫЕ
SMTP не предполагает каких-либо папок.
py.user.next
Фев. 9, 2015 09:09:46
Нет никаких папок в SMTP-протоколе.