5.7.57 SMTP in scheduled task

Aleksej Egorov 41 Reputation points
2026-10-13T16:30:46.2333333+00:00

Hello everyone. I’m trying to send an email from a scheduled task but am encountering an error. However, the script runs perfectly fine in an interactive session. I see the same behavior whether I use Send-MailMessage or the Send method of System.Net.Mail.SmtpClient.

Everything works fine if I provide the sender's credentials explicitly (either hardcoded or by importing them via Import-CliXml). In the previous installation on Server 2022 everything also was fine.

  • Client OS Version: 10.0.26100
  • PSVersion: 5.1.26100.33438
  • Exchange OS version: 10.0.26100
  • Exchange Server version: 15.2 (Build 1748.10)

Any ideas?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author
Deepesh Dhake 1,245 Reputation points
2026-10-13T22:04:15.92+00:00

The most likely cause is Credential Guard, which Server 2025 enables by default on domain-joined servers. Your 2022 box probably didn’t have it.Check:

(Get-CimInstance -Namespace root\Microsoft\Windows\DeviceGuard -ClassName Win32_DeviceGuard).SecurityServicesRunning  

If the output includes 1, it’s on. Test with it disabled.

Also rule out: the task set to "Do not store password" (no network credentials), or running as SYSTEM (authenticates as COMPUTER$).

Fix: keep using Import-CliXml (create the file as the task’s account on that server), or use an IP-scoped relay connector.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Newest
  1. Ronald Sabiiti 585 Reputation points Independent Advisor
    2026-10-13T16:54:41.5166667+00:00

    Hello @Aleksej Egorov

    Welcome to Microsoft Q&A!

    Thank you for your patience, and taking the time to elaborate on your concerns.

    This difference is expected: scheduled tasks run under a non‑interactive logon type and do not inherit cached credentials from your interactive session. That’s why implicit authentication fails, but explicit credentials succeed.

    Key Points.

    Interactive vs. scheduled context: Interactive sessions can reuse cached Kerberos/NTLM tokens; scheduled tasks cannot.

    Task Scheduler logon type: Runs as LOGON_BATCH, which restricts credential delegation.

    OS changes: Newer Windows builds enforce stricter credential handling compared to Server 2022.

    Fix Options.

    1. Run the task under a service account with SMTP permissions.

    Store credentials securely using Export-CliXml / Import-CliXml and load them in the script.

    Check Task Scheduler settings:

    “Run whether user is logged on or not” (requires stored password).

      “Run with highest privileges.”
      
      Consider modern authentication (OAuth, certificates) if your Exchange/SMTP server supports it.
      
    

    Relevant Documentation.

    Note: Scheduled tasks don’t inherit your interactive credentials. Use a service account or securely stored credentials (Import-CliXml) to ensure reliable email sending. Modern auth methods are recommended if available.

    I hope this helps to better understand the diagnostic options available and the risks involved.

    If this information was helpful, please click Accept Answer.

    Thank you for choosing Microsoft Q&A.

    Was this answer helpful?


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.