Forum Discussion
copy sent mail to sent folder
OS is Windows Server 2025. PS version is 5.1.17763.9121
I have been using a PS script for will over a year now to send an e-mail letting me know when a server backup successfully completes, and when it fails. I now have a need for emails sent using PowerShell to also be copied to the sent folder when sent. I've searched all over MS and other powershell support sites, and the best I can find deals with saving items in a shared mailbox folder. I'm not using a shared mailbox. I'm sending the e-mail from a comcast.com e-mail address. Where can I find guidance on doing what I need? For reference if it helps, the last line in my scripts that actually send the e-mail is below.
$SMTPClient.Send($SMTPMessage)
2 Replies
Your script sends through SMTP from a Comcast mailbox, but SMTP submission does not provide PowerShell a standard way to place a copy in that mailbox’s Sent folder. The Sent folder belongs to the mailbox service, so the server must offer it or the message must be sent through a mailbox API. First, test the same Comcast account in webmail and confirm whether it saves a Sent copy; that separates mailbox behavior from the script. Do not rely on a local Outlook Sent folder unless Outlook sends the message. If the mailbox is Microsoft 365 or Exchange Online, move the send operation to Microsoft Graph: its send-mail operation saves to Sent Items by default unless disabled. If this must remain Comcast SMTP, check Comcast’s documented SMTP settings or support options; otherwise archive a copy separately, because Windows PowerShell 5.1 cannot force a remote provider’s Sent folder to accept one.
- Conan3011Copper Contributor
$SMTPClient.Send($SMTPMessage) cannot save a copy of the message in the Sent folder.
System.Net.Mail.SmtpClient only submits the message to an SMTP server for delivery. SMTP does not provide access to mailbox folders, so there is no SmtpClient property or PowerShell option that you can add to make it save the message in Comcast’s Sent folder.
To do what you want, you need a second operation after the message has been sent successfully:
- Send the message through SMTP.
- Connect to the Comcast mailbox using IMAP.
- Append a copy of the same message to the Sent folder.
For Comcast, the IMAP server is:
- Server: imap.comcast.net
- Port: 993
- SSL/TLS: enabled
PowerShell/.NET’s System.Net.Mail classes do not provide an IMAP client, so this cannot be done using $SMTPClient alone.
One option is MailKit/MimeKit. MailKit supports both SMTP and IMAP, including appending a MimeMessage to the mailbox’s Sent folder. For a new implementation, I would probably create the message as a MimeMessage, send it through MailKit’s SMTP client, and then append that same message through its IMAP client. This avoids having to recreate the message after it has already been sent.
Conceptually:
Create message
|
+--> SMTP --> send message
|
+--> IMAP --> append same message to Sent
If you want to keep the existing System.Net.Mail script unchanged, you would still need to add an IMAP-capable library for the second operation; System.Net.Mail itself cannot perform it.
Also make sure that third-party email access is enabled in the Comcast mailbox settings, otherwise the IMAP connection will be rejected.
So the issue is not Windows Server or PowerShell 5.1 specifically. It is that sending through SMTP and storing a message in a mailbox folder are two separate operations.