Forum Discussion
copy sent mail to sent folder
$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.