A python wrapper for mailing with any email-address. Using win32.client and Outlook or yagmail.
Project description
Work in progress...
Easemail
The package has been created gradually while trying to make sending automatic mails in Python as easy as possible. I ended up with a package that basically just adds some features to yagmail. These are:
- Adding the possibilty to send emails via Outlook
- Adding list as tables to emails
- Adding the possibility to include inline images by putting this in an extra line inside of the text block, e.g.
"""This is some text, followed by an inline picture /path/to/som/image.png followed by more text. """
- Determine the SMTP-server, security protocol and port using a database
- Added user files where the SMTP-Server, Security-Protocol and Port are stored, to make once determined data easier to reuse.
Therefore, it heavily depends on the yagmail and pywin32 project.
So, make sure to check out their project pages on Github and leave a star if you like this one, as the actual work happens there!!!
Sending emails can be done in the same way as with yagmail:
import easemail
ema = easemail('mail_account')
hmtl = """
<html>
<body>
<p>Hi,<br>
How are you?<br>
You can find the easemail project
<a href="https://github.com/NicDom/easemail">here.</a>
</p>
</body>
</html>
"""
contents = ['Some body including text. There is also hmtl in this mail. A document is attached', html, 'document.pdf']
easemail.send('to@domain.com','subject', contents)
but mail_account
can be either a valid mail address, a credential file for some OAuth2 authentication using a gmail address, just 'outlook'
to use Outlook or an alias for an user file (see below). See further instructions below.
Installation
pip install easemail
Usage
There are three different usage cases:
Case 1: Outlook
If you are using Windows and want to use your Outlook Application to send mails, there are two ways to tell easemail. The first is to call easemail via
ema = easemail('outlook')
easemail will then give you a list of the in your Outlook Application registered email-addresses and lets aou choose one. If there is only one, easemail will use that one.
Alternatively, you may intialize easemail using the email address in your Outlook Application you are intending to use.
Case 2: Gmail
If you do want to use a gmail adress, there are again two ways to tell easemail. Either by giving it the path to your credential file for the OAuth2 authentification, i.e. via
ema = easemail('path/to/credential_file.json')
or by giving your gmail address
ema = easemail('yourgmailname@gmail.com')
However, as it is strongly recommended to use the authentification via OAuth 2 due to the possibility to revoke tokens, easemail will ask for the path to a credential file. If None is given it then first asks for the client ID and the client secret before asking for a password. You are then offered the option to store your password in a keyring.
Of course, you can also give your password right from the beginning by running (NOT RECOMMENDED):
ema = easemail('yourgmailname@gmail.com', 'your_password')
Case 3: Any email address
If you want to use any email address, just initialize easemail via
ema = easemail('yourmailaddress@domain.com')
easemail will then try determine the SMTP-server, security protocol and port using a database. If this fails, you will be ask for the missing information.
As before, you you will be asked for a password, which can be stored in some keyring if you desire. Of course, the password can again be given as the second argument, when initializing easemail.
User file
If easemail is able to connect to SMTP-Server using the given Server, Protocol and Port it, stores the gathered information in the file EMAIL_ADDRESS(without @...)--EMAIL_ADDRESS.json
.
Thereby simplifying the reuse of the gathered information in future projects.
Email contents
The email contents can follow the same syntax as proposed by the yagmail package. However, I added two features:
- If contents contains a list, this list will be translated to html code (and plain text) and included into the mail.
- Inlnine images can now just be put inside of the text body. Therefore one has just to put the path of the image in some extra line inside of the body, e.g.
"""This is some text, followed by an inline picture /path/to/som/image.png followed by more text. """
Feedback
I do appreciate every kind of feedback and will try to respond to issues in 24 hours at Github.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file easemail-0.0.3.tar.gz
.
File metadata
- Download URL: easemail-0.0.3.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 716c349b9c9561fd94e3ada3a5160940f8ff5ae2d04c56c0ea8b1537c06c89da |
|
MD5 | 318edb2c77f3fdd4669d51dbcfb989a6 |
|
BLAKE2b-256 | 343393bed1db9bbab70ac9e49fad6bc4d47e18d07364c43a649a3fb178c67ce0 |
File details
Details for the file easemail-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: easemail-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63ab340bd69b041c128eaceb77735be725d49a3010774ceca9d787f3dd135357 |
|
MD5 | c5c9fa1856c917324d1097c3846f2ebc |
|
BLAKE2b-256 | dd0ff6ea84bf6006b70c5ec46809e6301582a1a2b5d6ceec30a68f2413b573f7 |