Skip to content

Conversation

@Swiftyos
Copy link
Contributor

Currently if the smtp server is not configured currently it results in a platform error. This PR simplifies the error handling

Changes 🏗️

  • removed default value for smtp server host.
  • capture common errors and yield them as error

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • Checked all tests still pass

@Swiftyos Swiftyos requested a review from a team as a code owner November 20, 2025 11:47
@Swiftyos Swiftyos requested review from 0ubbe and ntindle and removed request for a team November 20, 2025 11:47
@github-project-automation github-project-automation bot moved this to 🆕 Needs initial review in AutoGPT development kanban Nov 20, 2025
@netlify
Copy link

netlify bot commented Nov 20, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit 48546fd
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/6920c30e10b6290008fdeaca

@coderabbitai
Copy link

coderabbitai bot commented Nov 20, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch swiftyos/open-2825-email_blockpy-blockunknownerror-errno-2-name-or-service-not

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Nov 20, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 48546fd
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/6920c30e05f68800098cc017

@qodo-merge-pro
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

TLS Handling

STARTTLS is always attempted on connection, but many servers require SSL (port 465) or do not support STARTTLS on the configured port. Consider making TLS/SSL behavior configurable and conditionally using SMTP_SSL or skipping STARTTLS.

    with smtplib.SMTP(smtp_server, smtp_port, timeout=30) as server:
        server.starttls()
        server.login(smtp_username, smtp_password)
        server.sendmail(smtp_username, to_email, msg.as_string())

    return "Email sent successfully"

async def run(
    self, input_data: Input, *, credentials: SMTPCredentials, **kwargs
) -> BlockOutput:
    try:
        status = self.send_email(
            config=input_data.config,
            to_email=input_data.to_email,
            subject=input_data.subject,
            body=input_data.body,
            credentials=credentials,
        )
        yield "status", status
    except socket.gaierror:
        yield "error", (
            f"Cannot connect to SMTP server '{input_data.config.smtp_server}'. "
            "Please verify the server address is correct."
        )
    except socket.timeout:
        yield "error", (
            f"Connection timeout to '{input_data.config.smtp_server}' "
            f"on port {input_data.config.smtp_port}. "
            "The server may be down or unreachable."
        )
    except ConnectionRefusedError:
        yield "error", (
            f"Connection refused to '{input_data.config.smtp_server}' "
            f"on port {input_data.config.smtp_port}. "
            "Common SMTP ports are: 587 (TLS), 465 (SSL), 25 (plain). "
            "Please verify the port is correct."
        )
    except smtplib.SMTPNotSupportedError:
        yield "error", (
            f"STARTTLS not supported by server '{input_data.config.smtp_server}'. "
            "Try using port 465 for SSL or port 25 for unencrypted connection."
        )
    except ssl.SSLError as e:
Error Message Clarity

The sender rejection message has a grammatical issue and lacks detail about which address was rejected; include the actual sender and improve wording for clarity.

except smtplib.SMTPSenderRefused:
    yield "error", (
        "Sender email address defined in the credentials that where used"
        "was rejected by the server. "
        "Please verify your account is authorized to send emails."
    )
Unhandled SMTP Exceptions

Some common SMTP errors like SMTPConnectError and SMTPHeloError are not explicitly handled; consider adding them to provide clearer feedback.

except smtplib.SMTPAuthenticationError:
    yield "error", (
        "Authentication failed. Please verify your username and password are correct."
    )
except smtplib.SMTPRecipientsRefused:
    yield "error", (
        f"Recipient email address '{input_data.to_email}' was rejected by the server. "
        "Please verify the email address is valid."
    )
except smtplib.SMTPSenderRefused:
    yield "error", (
        "Sender email address defined in the credentials that where used"
        "was rejected by the server. "
        "Please verify your account is authorized to send emails."
    )
except smtplib.SMTPDataError as e:
    yield "error", f"Email data rejected by server: {str(e)}"
except Exception as e:
    raise e

@deepsource-io
Copy link

deepsource-io bot commented Nov 20, 2025

Here's the code health analysis summary for commits 0edc669..48546fd. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ SuccessView Check ↗
DeepSource Python LogoPython✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@Swiftyos Swiftyos enabled auto-merge November 20, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🆕 Needs initial review

Development

Successfully merging this pull request may close these issues.

2 participants