Friday, June 29, 2018

Git & IONIC

git branch develop
git checkout develop //use
git commit -am "change channel"
git push ionic develop

git checkout master
git merge develop
git commit -am "merge conflict" // checkin local
git push origin // push to server
git push ionic master // push to server

git status

Friday, June 1, 2018

Dowload Attachment From Google Mail using IMAP


//POP is temporary only, so use IMAP better
//Nuget S22.IMAP

using (ImapClient client = new ImapClient("imap.gmail.com", 993, "Email", "App Password", AuthMethod.Login, true))
{
    IEnumerable<uint> uids = client.Search(
         SearchCondition.From("from@mail")
         .And(SearchCondition.SentSince(new DateTime(2018, 05, 01)))
          .And(SearchCondition.SentBefore(new DateTime(2018, 06, 01))), "Mail box Name");

    Console.WriteLine(uids.Count() + " Emails:");

    foreach (var uid in uids)
    {
        MailMessage message = client.GetMessage(uid,mailbox:"Mail box Name");

        Console.WriteLine(message.Subject);

        foreach (Attachment attachment in message.Attachments)
        {
            byte[] allBytes = new byte[attachment.ContentStream.Length];
            int bytesRead = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length);
            string destinationFile = @"C:\\myfile\\" + attachment.Name;
            BinaryWriter writer = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
            writer.Write(allBytes);
            writer.Close();
        }
   }
}