Giter Club home page Giter Club logo

Comments (5)

cole avatar cole commented on May 26, 2024 1

@rafaelrds ah, that's a good point. A better approach may be to use source_address after all then.

from aiosmtplib.

cole avatar cole commented on May 26, 2024

Source address is a string sent to the SMTP server when connecting, identifying the client by IP or hostname (or any string, really). That's not very clear anywhere in the docs, but I don't think it's appropriate to use as local_addr.

To me the question is if I should add another param to set local_addr. I don't really understand the use case for that, I guess it's required in some network setups? What seems like it should work for that is to establish a socket connection and pass it (via the sock) param. Does that solve your problem?

from aiosmtplib.

rafaelrds avatar rafaelrds commented on May 26, 2024

Yes @cole, it is for identifying the hostname and in our case, the sending machine can send e-mails for more than one domain, and has a few possible IPs when binding a socket. Let's say we are hosting from 1.2.3.4 but want to send from 1.2.3.5 if sending from domainA.com and 1.2.3.6 if it is from domainB.com (both are source addresses). I think adding a parameter to set local_addr might be the finest solution, so it can allow further customization. 🥇

Our current solution was to patch _create_connection method by creating a subclass of SMTP.
i.e.

class MySMTP(SMTP):
    async def _create_connection(self) -> SMTPResponse:
        ...
                else:
                    connect_coro = create_connection(
                        self.loop,
                        lambda: protocol,
                        host=self.hostname,
                        port=self.port,
                        ssl=tls_context,
                        ssl_handshake_timeout=ssl_handshake_timeout,
                        local_addr=(self._source_address, 0),
            )
        ...

As for the use case, some Email Service Providers defers messages when the client-ip field diverges from the IP presented at EHLO.

from aiosmtplib.

rafaelrds avatar rafaelrds commented on May 26, 2024

Hey @cole. I've noticed that the official CPython smtplib does use the source_address/hostname when creating a socket during connect() https://github.com/python/cpython/blob/master/Lib/smtplib.py#L339.

from aiosmtplib.

cole avatar cole commented on May 26, 2024

Closed by #167

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.