We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to send the Aspose generated email

Hi

With the help of Aspose.Email.MailMessage, we are creating a new email by setting the from address as the shared mailbox and with the help of Microsoft.Office.Interop.Outlook, we are moving it to the user’s draft folder and when we try to send that email we are getting the error message as “You Do not have the permission to send the message on behalf of the specified user.”

image.png (12.3 KB)

If the user’s directly create an email in outlook and changes the from address as shared mailbox. They can send the email without any issues. We have double checked and confirmed that user’s have access to send as the shared mailbox. Could you please help us to fix this?

@ImtMdu,

We have investigated the issue on our end and it doesn’t seems to be issue related with API. Actually, Exchange Server requires ‘Send As’ permissions to send the email message in this case. If you don’t have ‘Send As’ permissions, you can’t send the message.

Thanks for the reply. We do have “Send As” permission in Exchange. If we manually set the from address as the shared mailbox and send it, it works. It is only when Aspose is populating the from address for us.

Here is a workaround:

  1. Click From and remove the shared mailbox address by clicking on the X icon
    image.png (43.0 KB)

  2. Click Other E-Mail Address…
    image.png (39.7 KB)

  3. Begin typing the shared mailbox address in the “From” box and remove it by clicking on the X icon when it appears
    image.png (56.6 KB)

  4. Manually input your department address in the “From” box and click OK
    image.png (53.6 KB)

  5. Send your email

@ImtMdu,

I have observed the issue shared by you. We need to investigate it further and in order to proceed further we need to please share the code snippets for all steps including Interop.Outlook application. Please also share the versions of software along with access to account (if possible).

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

@ImtMdu,

Thank you for sharing the requested information. A ticket with ID EMAILNET-39851 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

@ImtMdu,

We suggest you to use email address for the user who is represented by the sender. I hope this will be helpful.

Aspose.Email.MailMessage mailMessage = new Aspose.Email.MailMessage();
// Contains the email address of the sender
// PidTagOriginalSenderEmailAddress
// https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagoriginalsenderemailaddress-canonical-property
mailMessage.Sender = "sender@domain.com";
// Contains the email address for the messaging user who is represented by the sender
// PidTagSentRepresentingEmailAddress
// https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagsentrepresentingemailaddress-canonical-property
mailMessage.From = "sharedMailbox@domain.com";
// Contains a list of display names for recipients that are to get a reply
// PidTagReplyRecipientNames
// https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagreplyrecipientnames-canonical-property
mailMessage.ReplyToList = "replyTo@domain.com";

mailMessage.Body = "any body";
mailMessage.Subject = "any Subject";

MapiMessage mailOutlookMapiMessage = MapiMessage.FromMailMessage(mailMessage);
mailOutlookMapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);

Thanks for the suggestion. Assigning user email address to mailMessage.Sender resolved the issue :slight_smile:

@ImtMdu,

Thank you for sharing feedback.