Coder Social home page Coder Social logo

Comments (7)

drfraser avatar drfraser commented on May 27, 2024 1

I ran pytest and some tests failed, all due to "'SMTPMock' object has no attribute 'starttls'" So it seems like the tests have never actually gone thru that particular 'elif' part before.

I will try to sort out this SMTPMock error

from prefect-email.

drfraser avatar drfraser commented on May 27, 2024 1

Thinking about things more deeply, I don't think having the SMTPType enum do double duty (security layer and also its default associated port) is the best of ideas. There are conventions to email and email systems, but not many hard requirements. And 465 was never a official standard and has been deprecated. There is too much flexibility when it comes to dealing with email systems and prefect-email ought to be flexible enough to handle systems other than the generic standards big names like Gmail use. And blindly assuming SSL/465 as defaults isn't great - office365.com uses POP3/IMAP with TLS (ports 993 or 995) if you're using an account to send msgs - outlook.com uses STARTTLS/587 according to Microsoft help... GMail is almost unusable now due to their AppPassword scheme... so having it be the default seems pointless...

Having smtp_server, smtp_type, and smtp_port be mandatory settings is not that much extra work for the coder using this library; it ensures there are no hidden assumptions and that the coder explicitly matches the code to the details of the system the code is interfacing to. This was initially my problem - I really didn't read the actual Prefect code before trying to use the library. I am slightly annoyed with myself, I saw the 465 value and that SSL == STARTTLS but it didn't quite register, and I wasted a few hours trying to debug what was wrong with my email server (wait, it was the code... I am a better sysadmin than coder, I guess)

from prefect-email.

drfraser avatar drfraser commented on May 27, 2024 1

GMail and AppPasswords work, but you have to have 2FA turned on for the account. The email I would like to use for Prefect related purposes is one I made to deal with my work at a university, so having 2FA on it is iffy (i.e. letting other people access the account would be a headache). Prefect has replaced the cron/bash setup I had. So I was more just grousing about Google's increased security. No, I can't use the uni email servers b/c it is Microsoft based and they have prevented any logins thru anything within the uni's internal network unless it is through a browser.

You are right about making smtp_port required. It is not essential for people who know what they're doing, it was just a suggestion.

I do like the idea of making explicit Credentials for different email providers, that would certainly save people some time. In any case, STARTTLS does need changed, so I will deal with that tomorrow.

from prefect-email.

ahuang11 avatar ahuang11 commented on May 27, 2024

I am slightly confused; I think it's basing it off SMTPType class, not the port number. Can you elaborate?
https://github.com/PrefectHQ/prefect-email/blob/main/prefect_email/credentials.py#L137-L140


            if smtp_type == SMTPType.SSL:
                server = SMTP_SSL(smtp_server, smtp_port, context=context)
            elif smtp_type == SMTPType.STARTTLS:
                server = SMTP(smtp_server, smtp_port)

from prefect-email.

drfraser avatar drfraser commented on May 27, 2024

SMTPType is an enum, its members are constants which are effectively integers, they have different names but SSL == STARTTLS if they're both 465. So the last two lines won't ever get executed even if smtp_type == SMTPType.STARTTLS. A simple test using the REPL will validate this

port 587 is the 'standard' port used when using STARTTLS anyhow, so from that perspective alone, it ought to not to be 465. When I fixed this, the code using my email server started working

from prefect-email.

ahuang11 avatar ahuang11 commented on May 27, 2024

This does return True; I've been enlightened!

from enum import Enum

class Test(Enum):
    
    A = 123
    B = 123

Test.A == Test.B

Thank you for elaborating on this.

from prefect-email.

ahuang11 avatar ahuang11 commented on May 27, 2024

I appreciate the thoughtful response!

Regarding, "GMail is almost unusable now due to their AppPassword scheme... so having it be the default seems pointless..." I was able to use their app password scheme with the defaults. Can you elaborate on this?

Regarding "prefect-email ought to be flexible enough to handle systems other than the generic standards big names like Gmail use", I think it's flexible right now with smtp_port kwarg overriding the default, but this also sparked an idea that maybe we should make those port values required, but have separate GmailServerCredentials, Office365ServerCredentials, etc, that sets these values for people who are unfamiliar with smtp types and ports and just wants to send an email.

If we do make it required, it's a breaking change and we do need to implement a DeprecationWarning period.

from prefect-email.

Related Issues (14)

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.