Share via

Issue with Getting email from Gmail from SQL Server 2019 Home Lab Server

mirza hussain 0 Reputation points
2026-04-06T06:31:12.9033333+00:00

Dear Team,

i have configured profile with account and giving smtp.gmail.com with 587 and 25 port each time but not sure why not getting email on my gmail inbox from db server that is running on windows server 2019 with sql server 2019. error msg says mail server not reachable and testconnection for smtp also being failed. server name, port, app password is correct but still not able to resolve this simple issue. Kindly guide me on this.

SQL Server | Other
0 comments No comments

2 answers

Sort by: Most helpful
  1. Lakshmi Narayana Garikapati 1,160 Reputation points Microsoft External Staff Moderator
    2026-04-06T09:49:11.35+00:00

    Hi mirza hussain,

    This is not a SQL Server configuration issue. The error “mail server not reachable” indicates that SQL Server cannot establish a network/TLS connection to Gmail’s SMTP service.

    Please check the following (these are mandatory for Gmail):

    Use only SMTP port 587

    Port 25 is usually blocked by ISPs, corporate firewalls, and cloud providers. Gmail also does not recommend using it.

    Use:

    Server: smtp.gmail.com

    Port: 587

    Enable SSL: Yes

    Use a Gmail App Password

    Gmail no longer allows SMTP access using the normal account password.

    Enable 2‑Step Verification on the Gmail account

    Generate an App Password

    Use the App Password in the Database Mail account

    Verify TLS 1.2 is enabled on Windows Server 2019

    Gmail requires TLS 1.2. If TLS 1.2 is disabled at the OS level, Database Mail will fail with this exact error.

    Test SMTP connectivity from the OS (important)

    From the SQL Server machine, run:

    PowerShellTest-NetConnection smtp.gmail.com -Port 587Show more lines

    If this fails, the issue is network/firewall related, and Database Mail will not work until outbound 587 is allowed.

    Check Database Mail logs for the exact failure reason

    SQLSELECT * FROM msdb.dbo.sysmail_event_log ORDER BY log_date DESC;Show more lines

    If the server is hosted (Azure VM, cloud, or corporate network), outbound SMTP is often blocked by policy. In that case, Gmail SMTP will not work until the firewall allows it.

    Thanks,

    Lakshmi.


  2. Q&A Assist
    2026-04-06T06:31:29.8366667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use the Database Mail troubleshooting steps in SQL Server and verify both Database Mail and SMTP connectivity.

    1. Verify Database Mail status and errors
      • In msdb, query sysmail_event_log to see why messages fail:
             SELECT *
             FROM msdb.dbo.sysmail_event_log
             ORDER BY log_date DESC;
        
      • If messages show status failed, join with sysmail_faileditems to see detailed errors as described in the Database Mail docs.
    2. Check message status in Database Mail views
      • Check whether messages are unsent, retrying, sent, or failed:
             SELECT mailitem_id, sent_status, last_mod_date
             FROM msdb.dbo.sysmail_allitems
             ORDER BY mailitem_id DESC;
        
      • If status is unsent:
        • Confirm the Database Mail external program is running and can be started by Service Broker.
        • Verify the DatabaseMail.exe file is in the correct directory and the SQL Server service account has permission to run it.
        • Check the Windows Application event log for Database Mail errors.
      • If status is retrying:
        • This indicates SQL Server can reach Database Mail but cannot reliably reach the SMTP server (network, firewall, or SMTP issue).
        • Use the Database Mail Configuration Wizard → View or change system parameters to adjust Account Retry Attempts and Account Retry Delay if the SMTP server is intermittently reachable.
      • If status is failed:
        • Use the error details from sysmail_event_log to identify whether the failure is due to authentication, SMTP rejection, or network problems.
    3. Confirm SMTP connectivity from the Windows Server
      • Since the error says “mail server not reachable” and SMTP test connection fails, verify:
        • The Windows Server 2019 host can resolve smtp.gmail.com (DNS).
        • Outbound ports 587 (TLS) and 25 are allowed through any local firewall and any upstream firewall/router.
      • If the server cannot reach smtp.gmail.com on 587 from the OS level, Database Mail will also fail.
    4. Validate Database Mail account configuration for Gmail
      • In the Database Mail account settings, confirm:
        • SMTP server: smtp.gmail.com.
        • Port: 587 (recommended for TLS). Port 25 is often blocked by ISPs and cloud providers.
        • SSL/TLS is enabled as required by Gmail.
        • Authentication uses the correct Gmail account and app password.
      • If the SMTP server refuses the message or authentication fails, this will appear in sysmail_event_log as “failure to authenticate” or “SMTP server refuses the email message.”
    5. Increase retry parameters only after connectivity is working
      • If the SMTP server is sometimes reachable but unstable, use the Database Mail Configuration Wizard → View or change system parameters and increase:
        • Account Retry Attempts (default 5).
        • Account Retry Delay (default 60 seconds).
      • This increases the time before Database Mail marks a message as permanently failed, but the root cause (network/SMTP reachability) still needs to be fixed.
    6. Clean up stuck unsent messages (optional)
      • After fixing connectivity and confirming new messages send correctly, old unsent messages can be deleted when they are the oldest in the queue:
             EXEC msdb.dbo.sysmail_delete_mailitems_sp
                 @sent_before = '2024-01-01';  -- example date
        

    Summary: Use sysmail_event_log and sysmail_allitems to see the exact failure, verify that Windows Server can reach smtp.gmail.com on port 587, ensure Database Mail is correctly configured with TLS and the Gmail app password, and adjust retry settings only after connectivity is confirmed.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.