Browse Source

ajoute un mode dry-run

master
François Poulain 2 years ago
parent
commit
c147f844c5
  1. 20
      mailing.py

20
mailing.py

@ -52,6 +52,11 @@ ma.add_argument(
help="Template of the mail to be sent",
)
parser.add_argument(
"-d", "--dry-run", action="store_true", help="Load data but don't send anything.",
)
parser.add_argument(
"-a",
"--attachement",
@ -130,7 +135,7 @@ def qencode_subject(message):
return message.replace(subjectstr, qsubjectstr, 1)
def send_message(message, to, attachment):
def send_message(message, to, attachment, args):
lines = message.split("\n")
@ -188,11 +193,12 @@ def send_message(message, to, attachment):
% (subjectvalue, fromvalue, dests[0], repr(dests))
)
# sending the mail to its recipients using the local mailer via SMTP
server = smtplib.SMTP("localhost", "25")
server.set_debuglevel(1)
server.send_message(msg)
server.quit()
if not args.dry_run:
# sending the mail to its recipients using the local mailer via SMTP
server = smtplib.SMTP("localhost", "25")
server.set_debuglevel(1)
server.send_message(msg)
server.quit()
if __name__ == "__main__":
@ -228,7 +234,7 @@ if __name__ == "__main__":
body = replace_values(bodytemplate, values)
# send message
send_message(body, recipient, attachment)
send_message(body, recipient, attachment, args)
# pause every 10 mails for 5 secs so that the MTA doesn't explode
counter = counter + 1

Loading…
Cancel
Save