Пример #1
0
        static void AddEmail()
        {
            EmailContext db    = new EmailContext();
            Email        email = new Email();

            email.emailbody         = "123124234q45q345q";
            email.EmailRecipientsId = 1;
            email.fromaddress       = "*****@*****.**";
            email.IdItem            = 114;
            email.ItemDescription   = "asdfwef24234234";
            email.subject           = "asdfasdf525asdfasdfasdfasdfasdf11123525";
            email.toaddress         = "*****@*****.**";



            try
            {
                for (int x = 0; x < 250; x++)
                {
                    System.Threading.Thread.Sleep(2000);
                    db.Emails.Add(email);
                    db.SaveChanges();
                    Console.WriteLine("Added email " + email.Id.ToString());
                    logger.Debug("Added email " + email.Id.ToString() + "\n\n");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not add email " + e.ToString());
                logger.Debug("Could not add email " + e.ToString() + "\n\n");
            }
        }
Пример #2
0
 public static void SendThroughGmail(EmailContext db, Email email, SmtpClient client)
 {
     client.Send(email.fromaddress, email.toaddress, email.subject, email.emailbody);
     //loggerwrapper.PickAndExecuteLogging("send email record " + email.Id);
     db.Emails.Remove(email);
     db.SaveChanges();
     Console.WriteLine("Deleted email " + email.Id);
 }
Пример #3
0
        public static void history()
        {
            EmailContext     db          = new EmailContext();
            List <HistoryID> histories   = db.HistoryIDs.ToList();
            List <Message>   messagelist = new List <Message>();
            ulong?           newesthistoryid;

            //email all history ids being processed

            while (true)
            {
                //System.Threading.Thread.Sleep(2000);

                while (checkhistoryiddb(db, out newesthistoryid))
                {
                    bool synced = fullsync(out messagelist, out newesthistoryid);
                    bool allrecordsmarkedasprocessed = true;

                    if (synced && messagelist.Count > 0)
                    {
                        foreach (Message message in messagelist)
                        {
                            string subjectline = message.Payload.Headers[0].Value;
                            int    index       = subjectline.IndexOf("AwolrID:");
                            string awolrid     = message.Payload.Headers[0].Value.Substring(index + 8);
                            string rebuild     = subjectline.Substring(0, index - 1);
                            //write to database
                            // Decode
                            string body           = " ";
                            var    encodedString2 = message.Payload.Parts[0].Body.Data;
                            if (encodedString2 != null)
                            {
                                var bytes2 = Decode(encodedString2);
                                body = System.Text.Encoding.UTF8.GetString(bytes2); // Hello Base64Url encoding!
                            }

                            string to = null;
                            try
                            {
                                EmailRecipients emailRecipients =
                                    db.EmailRecipients.Where(er => er.bidfakeemailaddress.Contains(awolrid) || er.pidfakeemailaddress.Contains(awolrid)).FirstOrDefault();

                                if (emailRecipients.bidfakeemailaddress == awolrid)
                                {
                                    subjectline = rebuild + " AwolrID:" + emailRecipients.pidfakeemailaddress;
                                    to          = emailRecipients.bidrealemailaddress;
                                }
                                else
                                {
                                    subjectline = rebuild + " AwolrID:" + emailRecipients.bidfakeemailaddress;
                                    to          = emailRecipients.pidrealemailaddress;
                                }

                                try
                                {
                                    Email email = new Email();
                                    email.emailbody         = body;
                                    email.EmailRecipientsId = emailRecipients.Id;
                                    email.fromaddress       = "*****@*****.**";
                                    email.toaddress         = to;
                                    email.IdItem            = emailRecipients.IdItem;
                                    email.subject           = subjectline;
                                    email.ItemDescription   = subjectline;
                                    db.Emails.Add(email);
                                    db.SaveChanges();
                                    Console.WriteLine("New Email Record Generated For Email " + email.Id);
                                }
                                catch (Exception e)
                                {
                                    logger.Debug("Could not create relay response email. Returning method" + e.ToString() + "--------------\n\n");
                                    return;
                                }
                                //ModifyMessageRequest mods = new ModifyMessageRequest();
                                //List<String> addedlabels = new List<String> { "Label_5558979356135685998" };
                                //List<String> removedlabels = new List<String> { };
                                //mods.AddLabelIds = addedlabels;
                                //mods.RemoveLabelIds = removedlabels;

                                //try
                                //{
                                //    service.Users.Messages.Modify(mods, userId, message.Id).Execute();
                                //}
                                //catch (Exception e)
                                //{
                                //    allrecordsmarkedasprocessed = false;

                                //    throw new Exception("message could not be marked as processed.messageid " + message.Id + e.ToString());
                                //}
                                try
                                {
                                    service.Users.Messages.Delete(userId, message.Id).Execute();
                                }
                                catch (Exception e)
                                {
                                    logger.Debug("Could not delete processed email" + e.ToString());
                                }
                            }
                            catch (Exception e)
                            {
                                logger.Debug("message could not be marked as processed. messageid: " + message.Id + ":" + e.ToString() + "--------------\n\n");
                            }
                        }
                    }
                }
            }
            //foreach (HistoryID historyid in histories)
            //{

            //    long id = historyid.History;
            //    try
            //    {

            //        ulong historyid_start_conversionresult;
            //        List<History> result = null;
            //        try
            //        {
            //            historyid_start_conversionresult = Convert.ToUInt64(id);
            //            result = ListHistory(service, "*****@*****.**", historyid_start_conversionresult, messagelist);

            //        }
            //        catch (OverflowException)
            //        {
            //            Console.WriteLine("{0} is outside the range of the UInt64 type.", historyid);
            //        }
            //        if (result != null)
            //        {

            //            //loggerWrapper.PickAndExecuteLogging("Was able to retrieve history" + id.ToString());
            //        }
            //    }
            //    catch (Exception e)
            //    {

            //    }
            //}
        }