read mails from exchange 2010 SP1 server using VB.net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: read mails from exchange 2010 SP1 server using VB.net

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    read mails from exchange 2010 SP1 server using VB.net

    Hi All,

    Iam a newbie to this field and iam assigned with a challenging task. I want to create a service in VB.net that helps us to read from exchange 2010 mailboxes. So kindly help me with some examples which can help me.

    Thanks,

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: read mails from exchange 2010 SP1 server using VB.net

    What have you done so far?

  3. #3
    Join Date
    Jul 2012
    Posts
    2

    Re: read mails from exchange 2010 SP1 server using VB.net

    Hi,
    I have tried using IMAPX component in c# and it is working fine in exchange 2003/2007 but not working in exchange server 2010 SP1. Here is the code that i wrote. kindlyn look below :

    private void button1_Click(object sender, EventArgs e)
    {

    ReadIMAPEmail();
    }

    private void ReadIMAPEmail()
    {
    string Mailserver = ConfigurationSettings.AppSettings["MailServer"];
    string MailServerPort = ConfigurationSettings.AppSettings["MailServerPort"];
    string MailServerUsername = ConfigurationSettings.AppSettings["MailServerUsername"];
    string MailServerPwd = ConfigurationSettings.AppSettings["MailServerPwd"];
    ImapClient imap = new ImapClient(Mailserver, Convert.ToInt32(MailServerPort), true);
    imap.IsDebug = true;
    try
    {
    WriteEventLogEntry("Checking for Server Authentication....");
    if (imap.Connection())
    //Iam getting the error message here after trying to connect to the server on particar port.But when i verified using telnet it is opening on that port

    {
    WriteLog("Loggin in to IMAP server.", Color.Green);

    bool Islogin = imap.LogIn(MailServerUsername, MailServerPwd);
    if (Islogin)
    {

    WriteLog("Connected to IMAP server.", Color.Green);

    ImapX.MessageCollection messages = imap.Folders["INBOX"].Search("ALL", true);

    foreach (ImapX.Message m in imap.Folders["INBOX"].Messages)
    {
    try
    {
    m.Process();
    List<imapx.mailaddress> ListTo = new List<imapx.mailaddress>();
    List<imapx.mailaddress> ListFrom = new List<imapx.mailaddress>();
    string textBody = m.TextBody.TextData;

    string htmlBody = m.HtmlBody.TextData;
    string strfromaddress = string.Empty;
    string strfromname = string.Empty;

    string strsubject = m.Subject.ToString();
    string strto = string.Empty;
    string strtoname = string.Empty;
    ListTo = m.To;
    ListFrom = m.From;
    for (int i = 0; i < ListTo.Count; i++)
    {
    strto = strto + ListTo[i].Address;
    strtoname = strtoname + ListTo[i].DisplayName;
    }
    for (int i = 0; i < ListFrom.Count; i++)
    {
    strfromaddress = strfromaddress + ListFrom[i].Address;
    strfromname = strfromname + ListFrom[i].DisplayName;
    }
    //delete message
    WriteLog("Deleting mail " + m.MessageId);
    m.SetFlag(ImapFlags.DELETED);

    }
    catch (Exception ex)
    {

    WriteLog("Error while reading email. " + ex.Message, Color.Red);
    }
    }

    imap.LogOut();
    }
    else
    {

    WriteLog("Cannot Login to IMAP Server. Please check your account details.", Color.Red);
    }
    }
    WriteLog("Finished checking IMAP mailbox....");
    }
    catch (Exception ex)
    {

    WriteLog("Error while connecting to IMAP server. " + ex.Message, Color.Red);

    }
    }

    private void WriteLog(string str)
    {
    WriteLog(str, Color.Black);
    }

    private void WriteLog(string str, Color mycolor)
    {
    lblStatus.Text = str;
    lblStatus.ForeColor = mycolor;
    }
    }

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: read mails from exchange 2010 SP1 server using VB.net

    Thanks for adding your code. Please have a look here to see how to post properly on this fourm :

    http://forums.codeguru.com/showthrea...for-more-info)

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: read mails from exchange 2010 SP1 server using VB.net

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center