//====Pop3 sample==================================//
//You can set default value by Default property
Pop3Client
.Default.UserName = "your server name";
Pop3Client
cl = new Pop3Client("your server name");
cl.UserName = "your name";
cl.Password = "pass";
cl.Ssl = false;
if (cl.Authenticate() == true)
{
   Int32 totalMailCount = cl.GetTotalMessageCount();
   Int32 MailIndex = 1;
   MailMessage mg = cl.GetMessage(MailIndex);
   String mailTo = mg.To;
   String mailCc = mg.Cc;
   String title = mg.Subject;
   String bodyText = mg.BodyText;
   String returnPath = mg["Return-Path"];
   //Save Image to your local hard disk
   foreach(MailContent ct in mg.Contents)
   {
      String filePath = "C:\MyFolder\" + ct.ContentDisposition.FileName;
      ct.DecodeData(filePath);
   }
}

//Delete selected mail from mailbox
Pop3Client pop = new Pop3Client("server name", 110, "user name", "pass");
pop.AuthenticateMode = Pop3AuthenticateMode.Pop;
Int64[] DeleteIndexList = new.....//It depend on your needs
cl.DeleteEMail(DeleteIndexList);

//Create MailMessage object from .eml file
String text = File.ReadAllText("C:\\MyMail.eml");
var mg = new MailMessage(text);

//====Imap sample================================//
//You can set default value by Default property
ImapClient
.Default.UserName = "your server name";

ImapClient
cl = new ImapClient("your server name");
cl.UserName = "your name";
cl.Password = "pass";
cl.Ssl = false;
if (cl.Authenticate() == true)
{
    Int32 MailIndex = 1;
    //Get all folder
    List<ImapFolder> l = cl.GetAllFolders();
    ImapFolder rFolder = cl.SelectFolder("INBOX");
    MailMessage mg = cl.GetMessage(MailIndex);
}

//Delete selected mail from mailbox
ImapClient pop = new ImapClient("server name", 110, "user name", "pass");
pop.AuthenticateMode = Pop3AuthenticateMode.Pop;
Int64[] DeleteIndexList = new.....//It depend on your needs
cl.DeleteEMail(DeleteIndexList);

//Get unread message list from GMail
using (ImapClient cl = new ImapClient("imap.gmail.com"))
{
    cl.Port = 993;

    cl.Ssl = true;
    cl.UserName = "xxxxx";

    cl.Password = "yyyyy";
    var bl = cl.Authenticate();
    if (bl == true)
    {
        //Select folder
        ImapFolder folder = cl.SelectFolder("[Gmail]/All Mail");

        //Search Unread
        SearchResult list = cl.ExecuteSearch("UNSEEN UNDELETED");

        //Get all unread mail
        for (int i = 0; i < list.MailIndexList.Count; i++)

        {
            mg = cl.GetMessage(list.MailIndexList[i]);
        }
    }
    //Change mail read state as read
    cl.ExecuteStore(1, StoreItem.FlagsReplace, "UNSEEN")

}


//Create draft mail to mailbox
using (ImapClient cl = new ImapClient("imap.gmail.com"))
{
    cl.Port = 993;

    cl.Ssl = true
    cl.UserName = "xxxxx";
    cl.Password = "yyyyy";
    var bl = cl.Authenticate();
    if (bl == true)
    {
        var smg = new SmtpMessage("from mail address", "to mail addres list"
            , "cc mail address list", "This is a test mail.", "Hi.It is my draft mail");
        cl.ExecuteAppend("GMail/Drafts", smg.GetDataText(), "\\Draft", DateTimeOffset.Now);
    }
}

//Idle
using (var cl = new ImapClient("imap.gmail.com", 993, "user name", "pass"))
{
    cl.Ssl = true;
    cl.ReceiveTimeout = 10 * 60 * 1000;//10 minute
    if (cl.Authenticate() == true)
    {
        var l = cl.GetAllFolders();
        ImapFolder r = cl.SelectFolder("INBOX");
        //You must dispose ImapIdleCommand object

        using (var cm = cl.CreateImapIdleCommand()) Caution! Ensure dispose command object
        {
            //This handler is invoked when you receive a mesage from server

            cm.MessageReceived += (Object o, ImapIdleCommandMessageReceivedEventArgs e) =>
            {
                foreach (var mg in e.MessageList)
                {
                    String text = String.Format("Type is {0} Number is {1}", mg.MessageType, mg.Number);
                    Console.WriteLine(text);
                }
            };
            cl.ExecuteIdle(cm);
            while (true)
            {
                var line = Console.ReadLine();
                if (line == "done")
                {
                    cl.ExecuteDone(cm);
                    break;
                }
            }
        }
    }
}


//Create SmtpMessage from MailMessage object
MailMessage mg = cl.GetMessage(MailIndex);
SmtpMessage smg = mg.CreateSmtpMessage();

//====Smtp sample==================================//
SmtpClient cl = new SmtpClient();
cl.ServerName = "your server name";
cl.Port = 25;
cl.EncryptedCommunication = SmtpEncryptedCommunication.Ssl;
//When use TLS instead of Ssl
cl.EncryptedCommunication = SmtpEncryptedCommunication.Tls;

SmtpMessage
mg = new SmtpMessage();
mg.Subject = "title";
mg.BodyText = "Hi.my mail body text!";
//Send by HTML format
mg.IsHtml = true;
mg.From = "my_address@mail.com";
mg.To.Add(new MailAddress("address@mail.com"));
//Add attachment file from local disk
SmtpContent 
ct = new SmtpContent();
ct.LoadData("C:\\myFile.xls");
mg.Contents.Add(ct);

var rs = cl.SendMail(mg);
//Check mail was sent or not
if (rs.SendSuccessfull == false)

{
    //You can get information about send mail is success or error reason
    var resultState = rs.State;

}


//====Add TraceListener sample================================//
SocketClient.TraceSource.Switch.Level = SourceLevels.All;
//Output to text file
StreamWriter
sw = new StreamWriter("C:\\TraceTest.txt");

sw.AutoFlush = true;
TextWriterTraceListener twtl = new TextWriterTraceListener(sw, "LogFile");
SocketClient.TraceSource.Listeners.Add(twtl);
//Out put to console window

ConsoleTraceListener ctl = new ConsoleTraceListener();
SocketClient.TraceSource.Listeners.Add(ctl);

//=====Twitter Sync sample==========================//

var cl = new TwitterClient(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var rr = cl.GetHomeTimeline();
foreach (var r in rr)
{
    Console.WriteLine(r.CreatedAt + ":" + r.Text);
}
cl.UpdateStatus("I feel happy!!"); //Add new tweet


//====Twitter Async sample(You can use this method on silverlight or WindowsPhone7)====//
var cl = new TwitterClient(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//Execute callback on UI thread
cl.SetDispatcher(dispatcher);
//Observe error event when async call
cl.Error += new EventHandler<AsyncCallErrorEventArgs>(OAuthClient_Error);

cl.GetHomeTimeline(rr =>
{
    foreach (var r in rr)
    {
        Console.WriteLine(r.CreatedAt + ":" + r.Text);
    }
});
cl.UpdateStatus("I feel happy!!", status => Console.WriteLine(status.CreatedAt + ":" + status.Text));


//====Dropbox OAuth sample=======================//
var ocl = DropboxClient.CreateOAuthClient("consumerKey", "consumerSecret");
var ai = ocl.GetAuthorizeInfo();
//Access ai.AuthorizeUrl by Browser and signin your account
//After signin you can get AccessToken
var
t = ocl.GetAccessToken(ai.RequestToken, ai.RequestTokenSecret);
var cl = new DropboxClient("consumerKey", "consumerSecret", t.Token, t.TokenSecret);

//====Dropbox Sync sample=======================//
var ai = cl.GetAccountInfo();

var cm1 = new GetMetadataCommand();
cm1.Path = "/MyFile.txt";
var rr = cl.GetMetadata(cm1);

var cm2 = new UploadFileCommand();
cm2.FolderPath = "/";
cm2.FileName = "FileNameOnDropbox.txt";
Byte[] bb = ...//You get byte data from your data source.
cm2.LoadFileData(bb);
cl.UploadFile(cm2);


//====Dropbox Async sample(You can use this method on silverlight or WindowsPhone7)===//
//Execute callback on UI thread
cl.SetDispatcher(dispatcher);
//Observe error event when async call
cl.Error += new EventHandler<AsyncCallErrorEventArgs>(OAuthClient_Error);
cl.GetAccountInfo(new GetAccountCommand(), ai => Console.WriteLine(ai.EMail));

var cm1 = new GetMetadataCommand();
cm1.Path = "/";
cl.GetMetadata(cm1, metaData => Console.WriteLine(metaData.Path));

//Observe Uploading data size.You can use it for progress bar feature.
cl.Uploading += (o, e) => Console.WriteLine("Total upload size is " + e.TotalSize);
var cm2 = new UploadFileCommand();
cm2.FolderPath = "/";
cm2.FileName = "FileNameOnDropbox.txt";
Byte[] bb = ...//You get byte data from your data source.
cm2.LoadFileData(bb);
cl.UploadFile(cm2, response => Console.WriteLine(response.BodyText));

//====Dropbox great articles from other site=================//
Use Dropbox with your ASP.NET application by _tasos


//====SugarSync Sync sample===========================//
var cl = new SugarSyncClient("mailaddress", "password", "AccessKeyID","PrivateAccessKey");
cl.Authenticate();
var rs = cl.GetUserInfo();


//====Rss Sync sample===============================//
var cl = new RssClient();
var fd = cl.GetRssFeed("http://www.website.com/rss.xml");
foreach (var item in fd.Items)
{
    //Read item property(Title,Link,PubDate) and do something.
}
//You can create new RssFeed instance from text data.
var fd1 = new RssFeed(System.IO.File.ReadAllText("C:\\rss.xml");

//====Rss Async sample=============================//
var cl = new RssClient();
cl.GetRssFeed("http://www.website.com/rss.xml", fd =>
{
    foreach (var item in fd.Items)
    {
        //Read item property(Title,Link,PubDate) and do something.
    }
});

//====OAuth2.0 Facebook(WindowsLive,Box.net) sample============================//
//Show Facebook sample.WindowsLive,Box.net has same static method
var
url = FacebookClient.CreateAuthorizeUrl("consumerKey", "redirect_url");
//Access ai.AuthorizeUrl by Browser and signin your account
//After signin, provider(Facebook,WindowsLive,Box.net,...etc) redirect to redirect_url that you specified 
//Url is like this (http://www.yourdomain.com/page1.aspx?code=1234abc
//Get code from querystring
var
t = FacebookClient.GetAccessToken("consumerKey", "consumerSecret", "redirect_url", code);

var cl = new FacebookClient(t.Token);


//====Facebook sample============================//
var cl = new FacebookClient(token);
var u = cl.GetUser("123456789");
u = cl.GetUser("123456789");
var d = cl.GetFriends(new GetFriendsCommand());
foreach (var f in d.FirendList)
{
    var friendName = f.Name;
    //Read other property and do something.
}






Last edited Jan 7 at 1:13 AM by higty, version 36

Comments

kfirbh Jun 19, 2013 at 12:15 PM 
i am trying to create c# appliction that connects to dropbox

var ocl = DropboxClient.CreateOAuthClient("ApplicationKey", "ApplicationSecret");

var ai = ocl.GetAuthorizeInfo();
//Access ai.AuthorizeUrl by Browser and signin your account
//After signin you can get AccessToken
var t = ocl.GetAccessToken(ai.RequestToken, ai.RequestTokenSecret);
var cl = new DropboxClient("ApplicationKey", "ApplicationSecret", t.Token, t.TokenSecret);

i get exception on var ai = ocl.GetAuthorizeInfo();
should i pass here the key and the secret i got from dropbox when regitring my app?