Skip to main content

A tool to send many mails from csv and a template

Project description

csvformatmail: A tool to format mails from csv and to send them

Installing

From pypi:

pipx install csvformatmail

You can also use pip if you do not want to install in a contained environnement.

Or developer version:

git clone <this repo>
cd csvformatmail
pip3 install -e .

(Optional) Enable completion (for bash or other shells using bash-completion)

mkdir -p ~/.local/share/bash-completion/completions
register-python-argcomplete csvformatmail > ~/.local/share/bash-completion/completions/csvformatmail

Example

Write a mail template:

From: My name <my-mail-address@example.org>
To: {{mail}}
Bcc: my-mail-address@example.org
Subject: Result of the last test

Dear {{firstname}} {{lastname.capitalize()}},

Your results of the last test are:

 - Part A: {{"{:.1f}".format(a)}}
 - Part B: {{"{:.1f}".format(b)}}

Therefore you {% if (a+b)/2>=10 %}pass{%else%}fail{%endif%} the test.
{% if (a+b)/2<10 %}
Another test session will be organized soon.
{%endif%}
-- 
Your teacher

Use a csv file with (at least) the columns firstname, lastname, mail, a and b:

firstname,lastname,mail,a,b,c
Jacques,MARTIN,jacques.martin@example.org,12.54441,14,1111.221
…

And the command if you use a distant smtp:

csvformatmail -h smtp.example.org -l mylogin template.txt -t a:float -t b:float listing.csv

Or if you have a local smtp:

csvformatmail template.txt -t a:float -t b:float listing.csv

Complex example

The template file can contain python definition, and all the rows for each column is accessible by the names allrows (default name, can be changed with arg --allrows-name). See the following template file:

From: My name <my-mail-address@example.org>
To: {{mail}}
Bcc: my-mail-address@example.org
Subject: Result of the last test

Dear {{firstname}} {{lastname.capitalize()}},

Your results of the last test are:

 - Part A: {{"{:.1f}".format(a)}}
 - Part B: {{"{:.1f}".format(b)}}

For you information, the statistics for part A are:
 - mean: {{'{:.2f}'.format(np.mean(allrows['a']))}}
 - standard deviation: {{'{:.2f}'.format(np.std(allrows['a']))}}.

Therefore you {% if (a+b)/2>=10 %}pass{%else%}fail{%endif%} the test.
{% if (a+b)/2<10 %}
Another test session will be organized soon.
{%endif%}
-- 
Your teacher.

And the command if you use a distant smtp:

csvformatmail -h smtp.example.org -l mylogin template.txt --np -t a:float -t b:float listing.csv

Misc

Consider use function fill and indent of textwrap module. For this you need use -b "import textwrap" or add a python preamble in you template file. e.g. in a template to rewrap to 72 chars:

{{textwrap.fill(somevalue, width=72)}}

Or, for rewrap and indent by > :

{{textwrap.indent(textwrap.fill(somevalue, width=70), "> ")}}

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

csvformatmail-1.0.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csvformatmail-1.0.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file csvformatmail-1.0.2.tar.gz.

File metadata

  • Download URL: csvformatmail-1.0.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for csvformatmail-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8e3ee72b878e2a966166351f8b372aee63124004f399527fe60b5fc0b1e0d2f1
MD5 aa351a93d36c3ac9ac6a19af52704cfc
BLAKE2b-256 076782017785e5558f86eb67a05c81ac5501d22eacc327f25930811f0eb93151

See more details on using hashes here.

File details

Details for the file csvformatmail-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: csvformatmail-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for csvformatmail-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 84d450863d9af07901fcf823fad71744d1072e4f449a9273989bcc117560bb70
MD5 6eb771ddf98b0c53f465a92ba766f24d
BLAKE2b-256 ab357cb8cd2172c717e3eb72828643b1ac56c735e3ed299f8b34cd1b8eea42c3

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