Skip to content

fix: smtp without username password#39987

Closed
NilanshBansal wants to merge 2 commits intoreleasefrom
fix/issue-39965/smtp-without-username-password
Closed

fix: smtp without username password#39987
NilanshBansal wants to merge 2 commits intoreleasefrom
fix/issue-39965/smtp-without-username-password

Conversation

@NilanshBansal
Copy link
Contributor

@NilanshBansal NilanshBansal commented Mar 31, 2025

Description

This is a potential fix for the SMTP issue that the user is facing.
More context here

Fixes #39965

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • SMTP connections now adjust authentication settings based on whether credentials are provided, ensuring more reliable behavior.
    • Enhanced error handling gracefully manages authentication failures with fallback connection attempts.
  • Refactor

    • Streamlined the configuration process for SMTP connection properties to improve clarity and maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

Walkthrough

The changes modify the SMTP plugin by conditionally setting the mail.smtp.auth property based on provided credentials. The testDatasource method now accepts a DatasourceConfiguration parameter instead of a Session and uses a new helper method, createProperties, to build SMTP properties. In case of authentication failure, the connection is retried without authentication. Additionally, error handling is updated to return a detailed DatasourceTestResult.

Changes

File(s) Change Summary
app/server/appsmith-plugins/smtpPlugin/.../SmtpPlugin.java - Conditional setting of mail.smtp.auth based on credentials
- Updated testDatasource method: parameter changed from Session to DatasourceConfiguration
- Added new private method createProperties to centralize SMTP property creation
- Modified error handling to retry connection without authentication on failure

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SMTPPlugin
    participant SMTPTransport

    Client->>SMTPPlugin: testDatasource(datasourceConfiguration)
    SMTPPlugin->>SMTPPlugin: createProperties(datasourceConfiguration)
    SMTPPlugin->>SMTPTransport: attempt connection (with auth if credentials provided)
    alt Authentication succeeds
        SMTPTransport-->>SMTPPlugin: Connection established
    else Authentication fails
        SMTPTransport-->>SMTPPlugin: Authentication error
        SMTPPlugin->>SMTPTransport: retry connection without auth
    end
    SMTPTransport-->>SMTPPlugin: Return connection status/error
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure SMTP plugin handles authentication conditionally based on provided credentials (#39965)

Possibly related PRs

Suggested labels

Bug, Task, ok-to-test

Suggested reviewers

  • mohanarpit
  • trishaanand
  • ApekshaBhosale

Poem

In our code's gentle sway, messages now take flight,
SMTP sings its conditional tune, precise and bright.
Properties crafted with care in every line,
Failure handled gracefully, the connection divine.
Cheers to a tweak that makes our emails shine!
🚀📧 Happy coding!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a118152 and 869767e.

📒 Files selected for processing (1)
  • app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (3)
app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (3)

213-234: Improved SMTP authentication handling

The conditional authentication setup properly handles SMTP servers that don't require credentials. By only setting mail.smtp.auth=true when username and password are provided, and false otherwise, the plugin now supports both authenticated and unauthenticated SMTP servers.


265-301: Enhanced testDatasource method with fallback authentication logic

Good change to accept DatasourceConfiguration directly instead of a Session. The fallback mechanism that retries without authentication when auth fails is particularly valuable for servers that advertise auth support but also allow unauthenticated access.


303-324: Well-designed createProperties utility method

This helper method eliminates code duplication and centralizes SMTP property creation logic in a single place. Good practice for maintainability.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Unplanned Work - Q&W Work items that are unplanned labels Mar 31, 2025
@NilanshBansal NilanshBansal requested a review from Copilot March 31, 2025 12:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes SMTP authentication issues when no username or password is provided and improves related error handling and configuration clarity.

  • Updated SMTP properties to delay setting auth until credentials are verified.
  • Modified the testDatasource method to recreate the session based on datasource configuration with proper fallback logic.
  • Introduced a helper method createProperties to centralize property construction.
Comments suppressed due to low confidence (1)

app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java:278

  • Ensure that the transport connection is closed after a successful connect to prevent potential resource leaks. Consider invoking transport.close() in a finally block or using a try-with-resources pattern if applicable.
transport.connect();

} catch (MessagingException e) {
log.error(e.getMessage());
invalids.add(SMTPErrorMessages.DS_CONNECTION_FAILED_TO_SMTP_SERVER_ERROR_MSG);
invalids.add(e.getMessage());
Copy link

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider standardizing the error message to provide more context rather than using the raw exception message, to help users better understand the failure.

Copilot uses AI. Check for mistakes.
@NilanshBansal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14172310831.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 39987.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-39987.dp.appsmith.com

@NilanshBansal
Copy link
Contributor Author

Closing this PR as the actual cause of the issue was the property mail.smtp.starttls.enable which was set to true initially even if the credentials were not passed.
Resolved the issue in this PR: #40005
cc: @sneha122 @vivek-appsmith @appsmithorg/query-widgets-pod

@NilanshBansal NilanshBansal deleted the fix/issue-39965/smtp-without-username-password branch April 1, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Unplanned Work - Q&W Work items that are unplanned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [A-force] Email Sending Issue After Appsmith Upgrade to Version 1.64 with MS Exchange Server

2 participants