Code Monkey home page Code Monkey logo

Comments (10)

VelikiiNehochuha avatar VelikiiNehochuha commented on May 14, 2024 2

To send via proxy you can use sock arg. For example:

from aiohttp_socks.proxy import create_proxy, ProxyType

proxy = create_proxy(
        host=proxy["hostname"], port=proxy["port"], proxy_type=ProxyType.SOCKS5)
await proxy.connect(host, port)

await send(
            message,
            hostname=None,
            port=None,
            validate_certs=False, # for validate server_hostname should be passed to starttls.
            username=source["username"],
            password=source["password"],
            start_tls=True,
            sock=proxy.socket
        )

`

from aiosmtplib.

cole avatar cole commented on May 14, 2024

Not currently, but I could have a look. What kind of proxy? SOCKS?

from aiosmtplib.

DeoLeung avatar DeoLeung commented on May 14, 2024

Http will be great, I'm using PySocks==1.6.7 to do the global http/socks proxy, but in production i just want to enable it for the email, I'll have a look at how to do the monkey patch correctly as well

from aiosmtplib.

starfear avatar starfear commented on May 14, 2024

Any changes?

aiohttp_socks looks deprecated it's proxy.socket functionality.
old version of aiohttp_socks does not allow to close socket

from aiosmtplib.

cole avatar cole commented on May 14, 2024

I was just going to add documentation for the sample above.

aiohttp_socks doesn't say deprecated in the repo, but it hasn't been updated in a while.

from aiosmtplib.

starfear avatar starfear commented on May 14, 2024

Oh yes I see.

Does aiosmtplib.send close connection ?
I see a lot of problems with duplicating FD's when I pass a sock I got from aiohttp_socks's open_connection -> writer -> .get_extra_info('socket'). It looks like lib closed the socket, but did not tell asyncio to delete the FD (writer.close()).

Socket I put as param to .send method has FD equal -1 after send operation.

from aiosmtplib.

starfear avatar starfear commented on May 14, 2024

Can you give example of usage aiosmtplib with socks, please?

from aiosmtplib.

cole avatar cole commented on May 14, 2024

@starfear the only example I have is the one above.

The send API opens and closes the connection to the server each time it's called. I'm not sure how we would close the writer if you're just passing the socket.

Using the SMTP client class directly (https://aiosmtplib.readthedocs.io/en/latest/client.html) should give you control over when the connection is opened/closed so you can sync it up with the proxy connect.

from aiosmtplib.

aweone avatar aweone commented on May 14, 2024

Will this feature be added soon? Are there any alternatives to the above example?

And can you provide some information for adding proxy support to the library yourself?

from aiosmtplib.

cole avatar cole commented on May 14, 2024

Probably not unless someone is interested in contributing it. I'd accept a PR for documentation of how it works.

from aiosmtplib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.