[issue45994] Add simple usage to email module

2021-12-06 Thread Taiga Katarao


Taiga Katarao  added the comment:

There are the simplest example to send text email and a little bit complicated 
example to an email with some files.

However, beginners like me want simple example to create an email composed of 
the combination of multipart/alternative and multipart/mixed.

There are many web sites to explain sending an email composed of 
multipart/alternative and multipart/mixed, but all of them use MIMEText and 
MIMEMultipart, which can be replaced and simplified with EmailMessage like 
below.

```
import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg['From'] = 'f...@example.com'
msg['To'] = 't...@example.com'
msg['Subject'] = 'Subject'

msg.add_alternative('Hello, world.', subtype='text')
msg.add_alternative('Helo, world.', subtype='html')
with open('example.pdf', 'rb') as f:
msg.add_attachment(
f.read(),
maintype='application',
subtype='pdf',
filename='example.pdf'
)

with smtplib.SMTP('SMTP_HOST', 'SMTP_PORT') as smtp:
smtp.starttls()
smtp.login('USER', 'PASSWORD')
smtp.send_message(msg)
```

Of cause I know we can obtain the code above from the combination of existing 
example codes, but it's a little bit difficult.

I guess the reason why they cannot find simple way partially because the 
official documentation does not provide example.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45994] Add simple usage to email module

2021-12-06 Thread Eric V. Smith


New submission from Eric V. Smith :

What sort of usage example would help you?

Is https://docs.python.org/3/library/email.examples.html lacking something?

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45994] Add simple usage to email module

2021-12-06 Thread Taiga Katarao


Change by Taiga Katarao :


--
assignee: docs@python
components: Documentation
nosy: docs@python, tarao1006
priority: normal
severity: normal
status: open
title: Add simple usage to email module
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com