Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#26 Code for Exchange EWS support posted here

open
nobody
None
5
2015-01-16
2009-02-26
Dworkin
No

Our internal task was to connect BTNet with MS Exchange 2007 with blocked POP3/IMAP. Another limitation was that we have only .Net 2 at our server. The only way to read e-mail from Exchange 2007 server was to use Exchange Web Services (EWS).

So I did small modification of btnet_service project
a. with the help of VS2008 I added web reference to our Exchange server
b. add new keys in config file
<!--
Work with Exchange 2007 Web Services
-->
<add key="UseEWS" value="1"/>
<add key="EWSFolder" value="c:\temp\EWS"/>

<!--
The way, how e-mail shoud be deleted at the Exchange side
1 HardDelete
2 MoveToDeletedItems
3 SoftDelete
-->
<add key="EWSDeleteType" value="2"/>

c. modified POP3Main::fetch_messages_for_projects so that btnet_service can use its internal functionality to have input from file (see attachment)
protected void fetch_messages_for_projects()
{
// Get the list of accounts to read
try
{
string sql = @"select
pj_id, pj_pop3_username, pj_pop3_password
from projects
where pj_enable_pop3 = 1";

    DataSet ds = get\_dataset\(sql\);

    foreach \(DataRow dr in ds.Tables\[0\].Rows\)
    \{

        if \(state \!= service\_state.STARTED\)
        \{
            break;
        \}

        write\_line\(string.Format\("processing project \{0\} using account \{1\}", Convert.ToString\(dr\["pj\_id"\]\), dr\["pj\_pop3\_username"\]\)\);

        if\(UseEWS == "1"\)
        \{
            EWS\_helper exchangeObj = new EWS\_helper\(\(string\) dr\["pj\_pop3\_username"\], \(string\) dr\["pj\_pop3\_password"\], EWSFolder, EWSDeleteType\);
            for \(int i = exchangeObj.InboxMailsNumber; i &gt; 0; i = exchangeObj.InboxMailsNumber\)
            \{
                MessageInputFile = exchangeObj.GetEMLFile\(\);
                fetch\_messages\(\(string\)dr\["pj\_pop3\_username"\], \(string\)dr\["pj\_pop3\_password"\], \(int\)dr\["pj\_id"\]\);
                exchangeObj.DeleteLastProcessingEmail\(\);
                write\_line\("sending Exchange command DELETE ITEM"\);
            \}
        \}
        else
            fetch\_messages\(\(string\)dr\["pj\_pop3\_username"\], \(string\)dr\["pj\_pop3\_password"\], \(int\)dr\["pj\_id"\]\);
    \}
\}
catch \(Exception e\)
\{
    write\_line\("Error trying to process messages"\);
    write\_line\(e\);
    return;
\}

}
d. add EWS_helper.cs filoe to project to work with EWS (see attachment)

That's it. May be this will help someone to resolve the same problem.

Regards,
Sergey

Discussion

  • Dworkin
    Dworkin
    2009-02-26

     
    Attachments
  • Dworkin
    Dworkin
    2009-02-26

     
    Attachments
  • Dworkin
    Dworkin
    2009-02-26

    File Added: POP3Main.cs

     
  • Corey Trager
    Corey Trager
    2009-02-28

    Thanks. (I don't want to add this code to the main codebase because I don't have a way to test it. But I hope it helps people that you posted it here.)

     
  • Corey Trager
    Corey Trager
    2009-02-28

    • priority: 5 --> 8
    • assigned_to: nobody --> ctrager
    • summary: add EWS support for btnet_service --> Code for Exchange EWS support posted here
     
  • Corey Trager
    Corey Trager
    2009-08-16

    • priority: 8 --> 7
     
  • Corey Trager
    Corey Trager
    2009-11-05

    • assigned_to: ctrager --> nobody
     
  • Corey Trager
    Corey Trager
    2009-11-05

    • priority: 7 --> 5