Skip to main content

A simple tool for sending mail by Python

Homepage

https://github.com/kongkongyzt/PyMailMan

Install

sudo pip install PyMailMan

Usage

  • To send the text

from PyMailMan import PyMailMan

mail = PyMailMan(host='smtp.qq.com', user='12345678', password='12345678')
mail.send(
    ['3456767@qq.com','testman@gmail.com'],
    'This is title',
    'This is the content'
)
print 'OK' if mail.status else mail.errMsg
  • To send the HTML

from PyMailMan import PyMailMan

mail = PyMailMan(host='smtp.qq.com', user='12345678', password='12345678')
mail.send(
    ['3456767@qq.com','testman@gmail.com'],
    'This is title',
    "<p style='color:red'>This is the content</p>"
)
print 'OK' if mail.status else mail.errMsg
  • To send the email with file

from PyMailMan import PyMailMan

mail = PyMailMan(host='smtp.qq.com', user='12345678', password='12345678')
#Recommand to write the absolute path of the file
mail.send(
    ['3456767@qq.com','testman@gmail.com'],
    'This is title',
    'This is the content',
    '/home/kongkongyzt/a.txt',
    '/home/kongkongyzt/b.txt'
)
print 'OK' if mail.status else mail.errMsg
  • To show the image in the mail content

mail = PyMailMan(host='smtp-mail.outlook.com', user='xxxxx@outlook.com', password='xxxx')
mail.send(
    ['783087000@qq.com'],
    'This is title',
    "Hello,The following image is the photo of last vacation in China, do you <span style='color:red'>like</span> it ? <img src='cid:1'>",
    "/home/kongkongyzt/a.jpg",
    "/home/kongkongyzt/b.docx",
    "/home/kongkongyzt/c.jpg"
)
print 'OK' if mail.status else mail.errMsg

You need to attention that the 1 in cid:1 means the second pictrue in your attachment,in this example is /home/kongkongyzt/c.jpg You should also know that once you choose one of the image in the attachment to show in the mail content by using <img src='cid:xx'>, the image file will not present in the attachList of the mail

Common mail smtp configure sample

assume the email address is 1234567@xx.com and password is 12345678 Here are some of the smtp configure example:

  • QQ Mail

PyMailMan(host='smtp.qq.com', user='1234567', password='12345678')
  • Gmail

PyMailMan(host='smtp.gmail.com', user='1234567@gmail.com', password='12345678')
  • Outlook

PyMailMan(host='smtp-mail.outlook.com', user='1234567@outlook.com', password='12345678')

Tips

  • You can manual defined the ports and the prefix

PyMailMan(host='smtp.gmail.com', user='1234567@gmail.com', password='12345678', ports=25, prefix='gmail.com')

Feedback

If you have any problem or issue, please contact me by opening an issue on the github homepage Homepage: https://github.com/kongkongyzt/PyMailMan

changelog

  • 0.1

init commit

  • 0.2

add send by HTML and send with file bug fix

  • 0.9

bug fix

  • 1.0

add support for sending file with relative path set the attaching file name as its’ real file name

Release files for PyMailMan 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyMailMan 1.0.0
File Size Uploaded
PyMailMan-1.0.0.tar.gz 3.2 kB Details

Release files / PyMailMan-1.0.0.tar.gz

Download URL PyMailMan-1.0.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f44468e8c44b2de0280731c9c166124e3840adffe26fad69c3613e01bd016245
BLAKE2b-256 checksum
How to use checksums
abe5454047e28756baa084f4ddcc674fb0f428287ffd12a9dccb1700a60214e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page