0

I have a problem when I want to send attachments through python, I ask it here because it works locally, but when migrating it to the server (Debian 10, Container in PROXMOX) it arrives corrupt for excel, I have no problems in wps office but in excel it marks me As if it were corrupt, I have iptables configured and according to me it already opened port 587, I changed the permissions of the folder where it is and also changed from user to root but nothing.

Any ideas ? I leave my iptables configuration and the python code

def sendMail(self, path):
        msg = MIMEMultipart()
        message = "FYI"
        password = "zzzzzzz"
        msg['From'] = "xxxxxx@tsiete.mx"
        desti = ["xxxxxx@tsiete.mx"]
        msg['To'] = ', '.join(desti)
        msg['Subject'] = "Correo Enviado Automaticamente"

        msg.attach(MIMEText(message))
        filename = path
        part = MIMEBase('applications', "octet-stream")
        part.set_payload(open(filename, "rb").read())
        encoders.encode_base64(part)
        # fp = open(filename, 'rb')
        # xls = MIMEBase('application', 'vnd.ms-excel')
        # xls.set_payload(fp.read())
        # fp.close()
        # encoders.encode_base64(xls)
        # xls.add_header('Content-Disposition', 'attachment', filename=filename)
        part.add_header('Content-Disposition', 'attachment', filename=filename)
        msg.attach(part)

        # create server
        server = smtplib.SMTP('smtp.ionos.com', 587)
        server.starttls()
        # Login Credentials for sending the mail
        server.login(msg['From'], password)
        # send the message via the server.
        server.sendmail(msg['From'], desti, msg.as_string())
        server.quit()
        os.remove(path)
        print("successfully sent email to %s:" % (msg['To']))

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:4718
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:27017
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3005
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3001 state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:submission
ACCEPT     udp  --  anywhere             anywhere             udp spt:587

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:27017
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3005
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3001 state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:submission
ACCEPT     udp  --  anywhere             anywhere             udp spt:domain
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:submission
ACCEPT     udp  --  anywhere             anywhere             udp spt:587

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.