Skip to content

Commit 551eb73

Browse files
committed
see Changelog v 0.1.1
1 parent 4271199 commit 551eb73

File tree

7 files changed

+81
-22
lines changed

7 files changed

+81
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v0.1.1
2+
## 26/09/2022
3+
4+
1. [](#new)
5+
* Add Option Delay
6+
* read Config (SMTP Server, user, pass ... from yaml config file)
7+
18
# v0.1.0
29
## 20/07/2022
310

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
## bulkmail.py: send bulk email to recipients in RecListFileName
22

33
This Program is a bulk Mailer, written in Python 3, intended exactly for what the name indicates:
4-
Sending Mail to a List of recipients, but, as opposed to the standard CC Feature from conventinal MUA's, each individual Mail ist personalised,
4+
Sending Mail to a List of recipients, but, as opposed to the standard CC Feature from conventional MUA's, each individual Mail ist personalised,
55
which means, each Recipient is addressed by his/her first Name.
66
Additionally, there is an Option 'nice' which can be used to make the Text even more nice (by using 'Liebe(r) XYZ' instead of 'Hallo XYZ').
77
And, yes, this nice Approach is even gender sensitive :-)
8-
For a History about Develompment, see the following [Blog Post](https://hoernerfranzracing.de/werner/blog/spam-schleuder-version-2-0).
8+
For a History about Develompment, see [this Blog Post](https://hoernerfranzracing.de/werner/blog/spam-schleuder-version-2-0).
99

1010
This is an improved Version from this [original gist](https://gist.github.com/wernerjoss/9ba0d815bb91d043f929d98670f99064).
1111
After some more improvements and future plannings (see TODO) I decided to make a real project out of it.
@@ -37,7 +37,5 @@ add Attach File Option 11.03.18
3737
fix some bugs 18.03.18
3838

3939
## TODO:
40-
- provide Option for configurable Delay between sent Mails to avoid possible Restrictions from SMTP Mailers w.r. to max. No# of sent Mails per Hour (or Day)
4140
- Localisation (say 'Hallo' or 'Hello', 'Liebe(r)' or 'Dear' to Recipients...)
42-
- move Configuration to separate yaml or json file
4341
- enable optional encryption for recipients from local keyring

bmgui.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
QVBoxLayout, QWidget, QFileDialog)
66

77
from PyQt5.QtCore import QProcess
8-
import sys
8+
import sys, os
99
from PyQt5 import QtCore, QtGui, QtWidgets
1010
import bmgui_layout
1111

@@ -36,21 +36,29 @@ def start_process(self):
3636
self.p.readyReadStandardError.connect(self.handle_stderr)
3737
self.p.stateChanged.connect(self.handle_state)
3838
self.p.finished.connect(self.process_finished) # Clean up once complete.
39-
ArgList = ['bulkmail.py']
39+
expath = os.path.abspath(os.path.dirname(__file__))
40+
exfile = expath + '/bulkmail.py' # CLI Version must reside in same Dir as GUI Version !
41+
ArgList = [exfile]
4042
if (self.checkBox.isChecked() == True):
4143
ArgList.append('-s')
4244
if (self.checkBox_2.isChecked() == True):
4345
ArgList.append('-l')
4446
if (self.checkBox_3.isChecked() == True):
4547
ArgList.append('-n')
48+
Delay = 0
49+
if (self.spinBox.value() > 0):
50+
Delay = self.spinBox.value()
51+
# self.message("Delay:" + str(Delay))
52+
ArgList.append('-d')
53+
ArgList.append(str(Delay))
4654
ArgList.append('-r')
4755
ArgList.append(self.RecFile)
4856
ArgList.append('-m')
4957
ArgList.append(self.MsgFile)
50-
if (len(self.Attachment) < 1):
58+
if (len(self.Attachment) > 1):
5159
ArgList.append('-a')
5260
ArgList.append(self.Attachment)
53-
# print(ArgList)
61+
print(ArgList)
5462
self.p.start("python3", ArgList) # JEDES arg extra !!
5563

5664
def openAttachmentDialog(self):

bmgui_layout.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def setupUi(self, MainWindow):
1818
self.centralwidget = QtWidgets.QWidget(MainWindow)
1919
self.centralwidget.setObjectName("centralwidget")
2020
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
21-
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 1041, 80))
21+
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 1281, 80))
2222
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
2323
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
2424
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
@@ -32,6 +32,12 @@ def setupUi(self, MainWindow):
3232
self.checkBox_3 = QtWidgets.QCheckBox(self.horizontalLayoutWidget)
3333
self.checkBox_3.setObjectName("checkBox_3")
3434
self.horizontalLayout.addWidget(self.checkBox_3)
35+
self.spinBox = QtWidgets.QSpinBox(self.horizontalLayoutWidget)
36+
self.spinBox.setObjectName("spinBox")
37+
self.horizontalLayout.addWidget(self.spinBox)
38+
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
39+
self.label.setObjectName("label")
40+
self.horizontalLayout.addWidget(self.label)
3541
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
3642
self.pushButton.setGeometry(QtCore.QRect(10, 100, 241, 40))
3743
self.pushButton.setObjectName("pushButton")
@@ -61,6 +67,7 @@ def retranslateUi(self, MainWindow):
6167
self.checkBox.setText(_translate("MainWindow", "Simulate"))
6268
self.checkBox_2.setText(_translate("MainWindow", "Create Log File"))
6369
self.checkBox_3.setText(_translate("MainWindow", "Nice"))
70+
self.label.setText(_translate("MainWindow", "Delay [s]"))
6471
self.pushButton.setText(_translate("MainWindow", "Select Recipients List File"))
6572
self.pushButton_2.setText(_translate("MainWindow", "Select Message File"))
6673
self.pushButton_3.setText(_translate("MainWindow", "Send Mail"))

bmgui_layout.ui

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<rect>
2020
<x>10</x>
2121
<y>10</y>
22-
<width>1041</width>
22+
<width>1281</width>
2323
<height>80</height>
2424
</rect>
2525
</property>
@@ -45,6 +45,16 @@
4545
</property>
4646
</widget>
4747
</item>
48+
<item>
49+
<widget class="QSpinBox" name="spinBox"/>
50+
</item>
51+
<item>
52+
<widget class="QLabel" name="label">
53+
<property name="text">
54+
<string>Delay [s]</string>
55+
</property>
56+
</widget>
57+
</item>
4858
</layout>
4959
</widget>
5060
<widget class="QPushButton" name="pushButton">

bulkmail.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
# ....add Attach File Option 11.03.18
1515
# ....fix some bugs 18.03.18
1616

17-
import getopt, sys
17+
import getopt, os, sys
1818
import smtplib
1919
from email.utils import formatdate
20-
import datetime
20+
import time, datetime
2121
from email.mime.text import MIMEText
2222
from email.mime.application import MIMEApplication
2323
from email.mime.multipart import MIMEMultipart
2424
import codecs
2525
import gender_guesser.detector as gender_detector
26+
import yaml
2627

2728
def send_email(FROM, TO, SUBJECT, TEXT, att_file):
2829

@@ -61,18 +62,36 @@ def send_email(FROM, TO, SUBJECT, TEXT, att_file):
6162
LogFile.write(logtext)
6263

6364
def usage(progname):
64-
print('usage: %s [-l -s -n] -r <RecListFileName> -m <MsgFileName> -a <AttachFileName>' % progname)
65+
print('usage: %s [-l -s -n -d Delay] -r <RecListFileName> -m <MsgFileName> -a <AttachFileName>' % progname)
6566
print('(-l = create Logfile, -s = Simulate, -n = Nice)')
6667
sys.exit(2)
6768

68-
# Config (global variables):
69-
FROM = 'George Bush <[email protected]>'
70-
# your smtp server credentials:
71-
smtp_server = "smtp.whitehouse.gov"
72-
user = "ghwbush"
73-
pwd = "obama"
74-
75-
# ....Defaults:
69+
# read config from yaml file:
70+
cfgpath = os.path.abspath(os.path.dirname(__file__))
71+
try:
72+
cfgfile = cfgpath + '/bulkmail.yaml' # config file must reside in same Dir as Program !
73+
with open(cfgfile, "r") as configfile:
74+
cfg = yaml.load(configfile, Loader=yaml.FullLoader)
75+
configfile.close()
76+
except: # Defaults:
77+
print("Warning: Config File not found, using Defaults (which will most likely NOT work!")
78+
cfg = {
79+
'FROM': 'George Bush <[email protected]>',
80+
'smtp_server': 'smtp1.whitehouse.gov',
81+
'user': 'gbush',
82+
'pwd': 'obama'
83+
}
84+
85+
# print('FROM:', cfg['FROM'])
86+
# print('smtp_server:', cfg['smtp_server'])
87+
# print('user:', cfg['user'])
88+
# print('pwd:', cfg['pwd'])
89+
# sys.exit(0)
90+
91+
FROM = cfg['FROM']
92+
smtp_server = cfg['smtp_server']
93+
user = cfg['user']
94+
pwd = cfg['pwd']
7695

7796
Simulate = False # nomen est omen :)
7897
Nice = False # True: Anrede 'Liebe(r)' statt 'Hallo' :)
@@ -86,10 +105,11 @@ def usage(progname):
86105
RecListFileName = ''
87106
MsgFileName = ''
88107
AttachFileName = ''
108+
Delay = 0
89109
try:
90110
progname = sys.argv[0]
91111
argv = sys.argv[1:] # wichtig !
92-
opts, args = getopt.getopt(argv,"lsnhr:m:a:",["RecListFileName=","MsgFileName=","AttachFileName="])
112+
opts, args = getopt.getopt(argv,"lsnhd:r:m:a:",["RecListFileName=","MsgFileName=","AttachFileName=","Delay="])
93113
#print ('opts',opts)
94114
#print ('argv',argv)
95115
except getopt.GetoptError as err:
@@ -104,6 +124,9 @@ def usage(progname):
104124
MsgFileName = arg
105125
elif opt in ("-a", "--AttachFileName"):
106126
AttachFileName = arg
127+
elif opt in ("-d", "--Delay"):
128+
Delay = int(arg) # wichtig: type conv !
129+
# print ('Delay', Delay)
107130
elif opt == '-l':
108131
CreateLogFile = True
109132
# print ('CreateLogFile')
@@ -185,6 +208,8 @@ def usage(progname):
185208
print('Message %d from %s has been sent to: %s' % (lineNum, MsgFileName, TO))
186209
else:
187210
print('Message %d from %s would be sent to: %s' % (lineNum, MsgFileName, TO))
211+
if (Delay > 0):
212+
time.sleep(Delay)
188213
lineNum += 1
189214
LogMsg += line + '\n'
190215
if CreateLogFile:

bulkmail.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM: George Bush <[email protected]>
2+
pwd: obama
3+
smtp_server: smtp.whitehouse.gov
4+
user: ghwbush

0 commit comments

Comments
 (0)