> For the complete documentation index, see [llms.txt](https://zeliang-yao.gitbook.io/my-note-zeliang-yao/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zeliang-yao.gitbook.io/my-note-zeliang-yao/useful/email.md).

# Email

{% embed url="<https://realpython.com/python-send-email#getting-started>" %}

```python
import smtplib



sender = 'zeliang.yao-external@dpdgroup.com'
receivers = ['to@todomain.com']

message = """From: From Person <from@fromdomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"
   
   
import smtplib
s = smtplib.SMTP('smtp.office365.com', '587')
s.starttls()
s.login('zeliang.yao-external@dpdgroup.com', 'password')
s.sendmail('zeliang.yao-external@dpdgroup.com', 'zeliang.yao-external@dpdgroup.com, '', 'hello world')
s.quit()
```
