SMTP Proxy - Python - How To Use Them

This is an example on how to use SMTP HTTP Proxies and SOCKS5 Proxies with Python programming language

Sending Emails Made Easy with Python: Your Friendly Guide to SMTP, HTTP Proxy, and SOCKS5

Hey there, awesome Pythonistas! Are you ready to add another cool trick to your Python toolkit? Today, we're going to have some fun learning how to send emails using Python. Whether you're automating a friendly reminder, crafting a newsletter, or setting up alerts for your latest app, this guide has got you covered!

We'll dive into the nifty world of Python's email capabilities, exploring how to use SMTP for sending emails. But wait, there's more! We're not just sending emails the standard way. We'll also learn how to send them through an HTTP proxy and SOCKS5, making sure your email game is top-notch and versatile.

Don't worry if this sounds a bit technical – I promise to keep things light, easy to understand, and, most importantly, fun. We’ll go through each step together, breaking down the hows and whys, so you'll be an email-sending ninja in no time.

After this friendly introduction, we’ll jump straight into the code. You'll see how simple and powerful Python can be for these tasks. Ready to start? Let’s get emailing!

import smtplib
import socks


PROXY_USERNAME = "REPLACE_WITH_YOUR_USERNAME"
PROXY_PASSWORD = "REPLACE_WITH_YOUR_PROXY_PASSWORD"
HOST = "REPLACE_WITH_YOUR_PROXY_IP"
PORT = 25252   # REPLACE_WITH_YOUR_PORXY_PORT

# Comment or remove the TYPE you are not using, it's important to select the type of your proxy
TYPE = socks.HTTP
TYPE = socks.SOCKS5


def _smtplib_get_socket(self, host, port, timeout):
    return socks.create_connection(
        (host, port),
        30,
        self.source_address,
        proxy_type=TYPE,
        proxy_addr=HOST,
        proxy_port=PORT,
        proxy_username=PROXY_USERNAME,
        proxy_password=PROXY_PASSWORD,
    )

smtplib.SMTP._get_socket = _smtplib_get_socket

SMTP_USER = 'REPLACE_WITH_YOUR_SMTP_USER'
SMTP_PASS = 'REPLACE_WITH_YOUR_SMTP_PASSWORD'

RECIPIENT = 'REPLACE_WITH_YOUR_RECEIVER'
SENDER = 'REPLACE_WITH_YOUR_SENDER'
MESSAGE = "test message"

server = smtplib.SMTP('smtp.gmail.com', 25)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login(SMTP_USER, SMTP_PASS)
server.sendmail(SENDER, [RECIPIENT], MESSAGE)
server.quit()

The above example will send email through Gmail SMTP using proxy. The debug is set to 1, so you can see the full transport.

Please replace values inside the script and run it.

Buy Proxies now

HTTP Proxies or SOCKS5, Shared or Dedicated, Residential or Data-center we have them all.

Buy Now