Below is the code used to create the email by setting the from address as the shared mailbox
Aspose.Email.MailMessage mailMessage = new Aspose.Email.MailMessage();
mailMessage.From = "sharedMailbox@domain.com";
mailMessage.Body = "any body";
mailMessage.Subject = "any Subject";
MapiMessage mailOutlookMapiMessage = MapiMessage.FromMailMessage(mailMessage);
mailOutlookMapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
MemoryStream mailStream = new MemoryStream();
mailOutlookMapiMessage.Save(mailStream);
mailStream.Position = 0;
byte[] buffer;
buffer = mailStream.ToArray();
Response.Clear();
Response.ContentType = "application/octet-stream;";
Response.AddHeader("content-transfer-encoding", "binary");
Response.AddHeader("content-disposition", "attachment;filename=" + "Sample.msg");
System.Text.Encoding.GetEncoding(1252);
Response.BinaryWrite(buffer);
Response.End();
And, below is the code used to save / move email to draft folder
bool mailItemSavedToDraft = false;
object inspectorObj = this.Context;
if (inspectorObj is Outlook.Inspector)
{
Outlook.Inspector inspector = (Outlook.Inspector)inspectorObj;
try
{
object currentItem = inspector.CurrentItem;
if ((currentItem != null) && (currentItem is Outlook.MailItem))
{
Outlook.MailItem currentMailItem = (Outlook.MailItem)currentItem;
if (currentMailItem.Parent is Outlook.MAPIFolder)
{
Outlook.MAPIFolder folder = (Outlook.MAPIFolder)currentMailItem.Parent;
if (folder.Name == "Drafts")
{
mailItemSavedToDraft = true;
}
}
if (!mailItemSavedToDraft)
{
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Outlook.MAPIFolder targetFolder = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
Outlook.MailItem movedMail = null;
movedMail = currentMailItem.Move(targetFolder) as Outlook.MailItem;
movedMail.Save();
movedMail.Display(false);
}
}
}
catch (Exception ex)
{
}
}
Version of software
1. Aspose.Email - 18.11 (I tried with the latest version 20.5 and the issue still persists)
2. Microsoft.Office.Interop.Outlook - 15.0
3. Exchange 2016
4. Outlook 2013
5. Windows server 2016