Manually Add Sent Email to IMAP Sent Folder
SMTP-based components do not automatically store sent messages in a Sent folder because this is not part of the SMTP protocol. When the server does not provide this functionality, the message must be captured and manually added to an IMAP mailbox using the IMAP component's AppendToMailbox method.
First, save a copy of the sent email using MessageHeadersString and TransferText. For example:
// ...
StringBuilder message = new StringBuilder();
htmlmailer.OnTransfer += (sender, args) => {
message.Append(htmlmailer.Config("TransferText"));
};
htmlmailer.Send();
String header = htmlmailer.Config("MessageHeadersString");
String body = message.ToString();
After capturing the message, append it to the Sent folder using IMAP:
// ...
imap.Connect();
imap.MessageHeadersString = header;
imap.MessageText = body;
imap.Mailbox = "Sent Mail"; // The name of this folder will differ based on the IMAP server.
imap.SelectMailbox();
imap.AppendToMailbox(); //Append to IMAP.
Note: Folder names may vary by server; use ListMailboxes if needed.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.