0

I wrote an interactive Python script that sends an email from my gmail without using the browser:

#!/usr/bin/env python3

from smtplib import SMTP, SMTP_SSL
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from subprocess import run
from time import strftime


server = SMTP_SSL("smtp.gmail.com", 465)#Sending over SSL requires less lines of code and is safer than starttls


fromaddr = "the.****@gmail.com"

with open("/home/john/app-pwd", "r") as f:
    pwd = f.read()
     
server.login(fromaddr, pwd)

msg = MIMEMultipart()

run('geany /home/john/email.txt', shell=True) #opens a text editor for you 

with open("/home/john/email.txt", "r") as f:
    text = f.read()

msg["Subject"] = input("The subject?")

msg.attach(MIMEText(text, "plain")) #attaches the header and the text to the message object

pic = "/home/john/wowlogo.png"


attachment = open(pic, "rb")

p = MIMEBase("application", "octet-stream")
p.set_payload(attachment.read())

encoders.encode_base64(p)
p.add_header("Content-Disposition", f"attachment; filename={pic}")
msg.attach(p)

toaddr = "let.it@be.dark"

text2 = msg.as_string()
server.sendmail(fromaddr, toaddr, text2)
server.quit()

The scripr is named client.py. When I it ran it over tor, like so:

$ torsocks ./client.py

I got the following output:

1641299602 ERROR torsocks[499130]: Unable to resolve. Status reply: 4 (in socks5_recv_resolve_reply() at socks5.c:677)
1641299602 ERROR torsocks[499130]: Unable to resolve. Status reply: 4 (in socks5_recv_resolve_reply() at socks5.c:677)
1641299603 WARNING torsocks[499135]: [syscall] Unsupported syscall number 315. Denying the call (in tsocks_syscall() at syscall.c:605)
The subject?Do me good

The final line of the output is the script asking for the subject of the email. I did receive the email but I'm not sure whether it was sent via Tor. Was it? I know that Alphabet blocks accessing their services via Tor - I did occasionally overcome it with the help of a Tor bridge.

How might I utilize a bridge with torsocks when torifying my script? What would I have to edit in my torrc? The aim is to connect to Tor via bridge just to send an email, then restore the regular configuration and restart Tor.

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.