Exchange server - send email,move email to folder,delete email ,Read email RRS feed

  • Question

  • User-148788041 posted


    I have 4 filters likes

    1. From Address
    2. Date of email
    3. Subject
    4. Operator = less than,equal to ,less than equal to 

    I do not how to use filter and read email based on date or from address. 

    Also i need to move specific email to a folder in exchange.

    Based on filter i need to delete email

    Based on filter i need to move attachment to folder.

    Thursday, December 27, 2018 5:41 PM

All replies

  • User-943250815 posted

    Try Mailkit https://github.com/jstedfast/MailKit
    You can install it through Nuget

    Thursday, December 27, 2018 9:45 PM
  • User-893317190 posted

    Hi Guhananth,

    As jzero has said, you could use MailKit,

    Below is a simple sample of MailKit, I use gmail and imap as a test.

     using (var client = new ImapClient())
                        // For demo-purposes, accept all SSL certificates
                        client.ServerCertificateValidationCallback = (s, c, h, en) => true;
                        client.Connect("imap.gmail.com", 993, true);
                        client.Authenticate("ackerlyx@gmail.com", "yourmailpassword");
                        // The Inbox folder is always available on all IMAP servers...
                        var inbox = client.Inbox;
                       Response.Write("Total messages: "+ inbox.Count+"<br/>");
                    Response.Write("Recent messages:"+ inbox.Recent+"<br/>");

    // get a folder and append the message into the folder var newFolder= client.GetFolder("Social"); newFolder.Append(inbox.GetMessage(1));

    // delete the first message client.Inbox.AddFlags(new int[] { 0}, MessageFlags.Deleted,true); for (int i = 0; i < inbox.Count; i++) { var message = inbox.GetMessage(i); //loop through the attachment of the message foreach (var attachment in message.Attachments) {
    // save the attachment var fileName = attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name; using (var stream = File.Create(fileName)) { if (attachment is MessagePart) { var rfc822 = (MessagePart)attachment; rfc822.Message.WriteTo(stream); } else { var part = (MimePart)attachment; part.Content.DecodeTo(stream); } } } // get the subject of the message Response.Write( "subject:"+message.Subject+"<br/>");
    // get from of the message Response.Write("address:" + message.From + "<br/>"); Response.Write("<br/><br/>"); } client.Disconnect(true); }

    For move message , you could refer to the link below.


    Best regards,

    Ackerly Xu

    Friday, December 28, 2018 4:41 AM
  • User-148788041 posted
    That is for imap4.
    I am using Microsoft.exchange.webservices dll.
    Friday, December 28, 2018 5:07 AM
  • User-943250815 posted

    For EWS you can get more info here https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd877037%28v%3dexchg.140%29
    I already worked with EWS, all I can tell, there is not so much samples available, it uses a proper dialect, the way to work is not always clear and you need to have in mind it is a WebService.

    Friday, December 28, 2018 3:10 PM