How do I get value from the first line of a Text(txt) file?

Asked

Viewed 1,354 times

-1

So... as you can see, the variable target sets the email that will be sent the message.

However, I cannot add the value of the first line of the list.txt inside the variable target.

The idea of a broader view is that the script sends the emails, line by line, or else it adds the value of the first line, and at the end of the loop it removes this value from the list.txt and the variable so that a new value can be added.

To add the value of the first line of a text.txt file within a variable ?

(and then remove first line from the txt file to continue the upload cycle.. until the list is finished. for i in xrange(texto): )

# -*- coding: UTF-8 -*-
import smtplib
import datetime
import random
import getpass
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

class spammer():
def __init__(self):
    self.banner()
    self.spam()

def banner(self):
    print """                                                          

    By Mandrake Venom 2018
                                                      """

arq = open('./lista.txt', 'r')
texto = len(arq.readlines()) -1
valor = "" 
print "[+] Total de Emails [+] "
print "========================="
print texto 
print "========================="
print valor
arq.close()

def spam(self):
    # Credentials
    username = raw_input("Login [gmail]: ")
    password = raw_input("Senha: ")
    target = raw_input("Enviar email para: ")
    assunto = raw_input("Assunto: ")
    men = input("Body: ")

    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    try: server.login(username, password)
    except: print "[-] Authentication Error" ; exit()

    print "[!] Preparando para Enviar "

    try:
        for i in xrange(texto):             
            subj = assunto,  random.randrange(0,9999999999999)
            content = MIMEText(men, 'html')
            name = "fulano"
            date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )             
            msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % (name, target, subj, date, content)
            server.sendmail(username, target, msg)
    except smtplib.SMTPException:
            print "[-] An Error Occured During Process | " 
            print "[!] The target email might be wrong [Error] ===> ",target 
            exit()
    server.quit()
    print "[+]", target, " [Enviado] Continue ===>"

try:
spammer()
except KeyboardInterrupt:
print "\n[!] Tchau! byeee byeeeeee.... "
exit()

1 answer

3

Try this:

with open('lista.txt', 'r') as f:
    primeira_linha = f.readline()

The with will use the file and close and the readline will read the first line.

  • File "mail-spammer.py", line 22 print primeira_line Indentationerror: Unexpected indent

  • This error is how you indentified the code, has nothing to do with the code I posted Indentationerror, Python requires a "good" indentation.

  • I put it at the beginning of the code, and sent a print primeira_linha , I’ve tried it this way and even the other way for i in lines arquivo error... most google answers I’ve already been around

  • so, python I am gourd

Browser other questions tagged

You are not signed in. Login or sign up in order to post.