Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support proxy #19

Open
DeoLeung opened this issue Jun 20, 2017 · 10 comments
Open

support proxy #19

DeoLeung opened this issue Jun 20, 2017 · 10 comments
Labels
🚀 feature something that would be nice

Comments

@DeoLeung
Copy link

Hi,

in our production environment, we need a proxy to send email, is there any plan to support it?

thanks,

@cole
Copy link
Owner

cole commented Jun 22, 2017

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

@DeoLeung
Copy link
Author

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

@cole cole added this to the 1.1.0 milestone Jul 14, 2017
@cole cole added the 🚀 feature something that would be nice label Jul 14, 2017
@cole cole removed this from the 1.1.0 milestone Jun 28, 2019
@VelikiiNehochuha
Copy link

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
        )

`

@cole cole self-assigned this Aug 1, 2020
@starfear
Copy link

Any changes?

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

@cole
Copy link
Owner

cole commented Sep 18, 2020

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.

@starfear
Copy link

starfear commented Sep 18, 2020

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.

@starfear
Copy link

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

@cole
Copy link
Owner

cole commented Sep 19, 2020

@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.

@cole cole removed their assignment Apr 1, 2021
@aweone
Copy link

aweone commented Jul 11, 2023

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?

@cole
Copy link
Owner

cole commented Jul 12, 2023

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

@cole cole mentioned this issue Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 feature something that would be nice
Projects
None yet
Development

No branches or pull requests

5 participants