📜 ⬆️ ⬇️

Mass mailing from the console using mutt

Recently, I was faced with a task: it was necessary to send thousands of letters with a link to a survey to all students of our university.
The problem with mass mailing is that the entire list of personalized mailings is visible in the CC field.
I solved this problem through a simple mail client mutt.

Mutt is a text-based email client for Unix-like systems. It was originally written by Michael Elkins in 1995 and released under the GNU General Public License.


First of all, in the root folder of the user you need to create a configuration file:

$ joe ~/.muttrc 

')
Here we will explain to the program what is our name and what address the recipient will see:

set realname = "John Smith"
set from = "jsmith@whitehouse.gov"
set use_from = yes


After that you need to create the letter itself.

 $ joe ~/body 


The letter itself, of course, in html:

 <!DOCTYPE html> <html> <head> <meta http-equiv=«Content-Type» content=«text/html; charset=utf-8»> </head> <body> <p><font color="#2E7BE4"><em><strong>!</strong></em></font></p> <p align="justify">    , <strong><font color="#CA9E64">   ,      </font></strong>.      HTML       ,   ,    -,       (Outlook, Thunderbird  ..).</p> <p> <font color="#2E7BE4"><strong><i> </i></strong><br> </font> </p> </body> </html> 


Now we need a mailing list file, let's call it list.

 $ joe ~/list 


email@mail.com
email2@mail.com
… etc.


It is noteworthy that the list can be of any size.

Now that everything is ready, it's time to move on to the mailing list itself:

 $ for I in `cat list`; do cat body | mutt -e "set content_type=text/html" -a "attachment.pdf" -s " " -- $I < body;echo $I;sleep 3 ;done 


This simple script in the bash language sends one by one (for I in `cat list`; do cat body), to each address (- $ I), every three seconds (sleep 3 - so that the server will not accept us as spammers) a letter ( body) from the list (list) with the file attached by us (attachment.pdf) and shows the result of the work (echo $ I).

The command “set content_type = text / html” says that the letter should be formatted in html.

That's all, I hope my experience will be useful to you.

Source: https://habr.com/ru/post/183202/


All Articles