Skip to main content

Send mail from gmail using python

Project description

Description

This is a very simple package that enables you to send mail through gmail using python. It’s not a big deal, it does not read your emails, no calendars, no drafts… It does just one thing, sending emails (possibly with attachments).

Requirements

  • Python 3

  • pip3 for installation

Install

Using setup.py

git clone https://github.com/kindlychung/pygmail.git
cd pygmail
python3 setup.py install

Using pip:

From github:

pip3 install --upgrade git+https://github.com/kindlychung/pygmail.git

or from PyPI:

pip3 install --upgrade pygmail2

Security

It uses smtp, that’s all. You can always check the source code, of course

Usage

You need put your gmail account and password in ~/.pygmailrc, for example:

xyz@gmail.com
xyz_super_secret

From the shell:

echo "hi there" | gmailsend xxx@yyy.com --subj hi --attach /path/to/file
gmailsend xxx@yyy.com --subj hi --attach /path/to/file --body_file /path/to/bodyfile
## for help
gmailsend -h

From python shell you can do things like:

from pygmail2.Pygmail import mo
from pygmail2.Addr import ad
# send to one address
mo.sm(to_addr = "xyz@example.com", subject= "test", text = "<b>hi there</b>")
# send attachments
mo.sm(to_addr = "xyz@example.com", subject= "test", text = "<b>hi there</b>", attachments = ["/tmp/x.txt", "/tmp/y.png"])
# send to multiple addresses
mo.sm(to_addr = ["xyz@example.com", "aaa@bbb.org"], subject= "test", text = "<b>hi there</b>", attachments = ["/tmp/x.txt", "/tmp/y.png"])
# use html file as mail body
mo.smf(to_addr = ["xyz@example.com", "aaa@bbb.org"], subject= "test", mailfile = "/tmp/x.html", attachments = ["/tmp/x.txt", "/tmp/y.png"])

You can store an address book in the csv format in the ~/.pygmail/email.csv file. For example:

Xiao Lu,xl@eepcxx.org

Then you access this email address by:

ad.xiao_lu_xl_eepcxx_org

The advantage of this is that you got autocompletion for free.

To save some typing, you can put the following lines in ~/.pygmail/startup.py:

from pygmail2.Pygmail import mo
from pygmail2.Addr import ad

And in your ~/.bash_aliases you can say:

alias pym='PYTHONSTARTUP=~/.pygmail/startup.py ipython3'

Then every time you want to send an email, you can just start it up by pym.

Change log

  • single recipient and single attachment now don’t require using list

  • Enabled attachments

  • Email address autocompletion

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygmail2-0.3.4.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file pygmail2-0.3.4.tar.gz.

File metadata

  • Download URL: pygmail2-0.3.4.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pygmail2-0.3.4.tar.gz
Algorithm Hash digest
SHA256 007ea7cdd4098a76350ff1b0e12861570c9fc63ec200733d77605867462d746e
MD5 f120fb2da070ee1a5dfea164cff1f4b1
BLAKE2b-256 c7e250d1def5ce412698c1d9f2bd826ddc5cac2ef4255eeace5f652fd1504bf0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page