Search code examples
c#exceptionexchangewebservices

'MessageDisposition' has to be set to 'SaveOnly' when sending mail via EWS


Whenever I try to send a mail with the following code via EWS I get the Exception: "'MessageDisposition' has to be set to 'SaveOnly'". (SendAndSaveCopy does the same)

    public static void SendMail(string from, string to, string subject, string body)
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        service.UseDefaultCredentials = true;
        service.AutodiscoverUrl(from, RedirectionUrlValidationCallback);

        try
        {
            EmailMessage message = new EmailMessage(service);
            message.IsAssociated = true;
            message.ToRecipients.Add(new EmailAddress(to));
            message.Subject = subject;
            message.Body = body;

            message.Send();
        }
        catch (Exception ex)
        {
            new ExceptionMessageBox(ex, "Unable to send Mail: " + subject).Show();
        }
    }

Does anybody have an idea why this happens and how to fix it?


Solution

  • You shouldn't be doing this

    message.IsAssociated = true;

    That isn't valid when you sending messages its only valid for creating a FAI (Folder Assoicated Item) in a folder