Aug-24-2017, 04:40 AM
Hello! I am new to python. I found this code, and it works good, but I want to make a small change - I want that when I input subject, it automatically adds number 1 in the end of the subject, and for every new e-mail send, increments added number by value of one. I tried everything I can find, but it always crashes.
May be someone can pinpoint the right approach?
For example, if I enter in subject line "Test", and set amount to 3 e-mails, it should send 3 e-mails with subjects:
Test 1
Test 2
Test 3
The code I have so far.


For example, if I enter in subject line "Test", and set amount to 3 e-mails, it should send 3 e-mails with subjects:
Test 1
Test 2
Test 3
The code I have so far.
print("Loading...") from time import strftime, localtime, sleep import os import smtplib def senda(msg, subject, to, amount, frm, password): import time import sys import smtplib num = 0 left = amount server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() global successful successful = 0 body = 'Subject: %s\n%s' % (subject, msg) try: server.login(frm, password) except: from time import sleep print("Error logging in.") sleep(5) import sys sys.exit() else: for i in range(amount): try: server.sendmail(frm, [to], body) except: pass else: successful += 1 print("%d emails sent" % successful) while True: time = strftime("%Y-%m-%d %H:%M:%S", localtime()) user_email = input("Email: ") user_pass = input("Password: ") to = input("To: ") subject = input("Subject: ") message = '\n' + input("Message: ") while True: amt = input("Amount: ") try: amt = int(amt) except: pass else: break senda(message, subject, to, amt, user_email, user_pass)For all the answers, thanks in advance! :)