none
how to use Load method to open a created Mail EWS c# RRS feed

  • Question

  • Hey!

    Im making a program that are creating emails and i want to make so the email opens (load) but cant get it to work..
    Any ideas how i can make it work?
    Here is my code so far:
                    mejlÄmne = "Skarp uppgradering av PM " + KundNamn + " klar!";
                    mejltext = "Hej," +
                    "<br><br>" +
                    "Nu är skarp uppgradering av er skarpa PM installation klar. " +
                    "<br>" +
                    "Om ni har några frågor eller stöter på några problem så får ni gärna återkomma." +
                    "<br><br>" +
                    "Med Vänliga Hälsningar" +
    
                    "<br><br>";
    
                    EmailMessage email = new EmailMessage(service);
                    email.ToRecipients.Add(emailTillKund);
                    email.CcRecipients.Add(CopyTo);
                    email.Subject = "Skarp uppgradering av PM " + KundNamn + " klar!";
                    email.Body = new MessageBody(mejltext);
                    email.Save();
                    email.Load();

    Friday, March 6, 2020 4:49 PM

All replies


  • Hi Carlo Goretti,
    Based on your description, I can't reproducr the situation.
    And I use the load method to write a code example you can refer to.

    private static bool RedirectionUrlValidationCallback(string redirectionUrl)
    {
        // The default for the validation callback is to reject the URL.
        bool result = false;
        Uri redirectionUri = new Uri(redirectionUrl);
        // Validate the contents of the redirection URL. In this simple validation
        // callback, the redirection URL is considered valid if it is using HTTPS
        // to encrypt the authentication credentials. 
        if (redirectionUri.Scheme == "https")
        {
            result = true;
        }
        return result;
    }
    private void button1_Click(object sender, EventArgs e)
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new WebCredentials("emailAdress", "password");
        service.AutodiscoverUrl("emailAdress", RedirectionUrlValidationCallback);
        service.TraceEnabled = true;
        service.TraceFlags = TraceFlags.All;
        EmailMessage email = new EmailMessage(service);
        email.ToRecipients.Add("emailAdress");
        email.Subject = "Test";
        email.Body = new MessageBody("Hello World!!!");
        email.Save(WellKnownFolderName.Drafts); 
        email.Load(new PropertySet(EmailMessageSchema.MimeContent));
        MimeContent mimcon = email.MimeContent;
        MemoryStream fileContents = new MemoryStream();
        fileContents.Write(mimcon.Content, 0, mimcon.Content.Length);
        fileContents.Position = 0;
        var result = fileContents;
    }

    Here are some related documents you can refer to.
    [Communicate with EWS by using the EWS Managed API]
    [C# (CSharp) Microsoft.Exchange.WebServices.Data EmailMessage.Load Examples]
    Hope these are helpful for you.
    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 9, 2020 7:20 AM
  • Hi Carlo Goretti,
    Has your problem been solved? If it is resolved, we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 12, 2020 9:01 AM