Example #1
0
        private static void InitProxy()
        {
            IEmail email163 = new Email163(CommonAppSetting.Instatance.UserName,
                                           CommonAppSetting.Instatance.Password);

            #region Fetch Proxy File
            var path = Path.GetTempFileName();
            try
            {
                email163.SaveFirstAttachement(CommonAppSetting.Instatance.Subject, path);
            }
            catch (Exception)
            {
                Log.Warn("No Proxy File can be fund");
                return;
            }

            if (!File.Exists(path) || FileHelper.GetFileSize(path) <= 0)
            {
                return;
            }
            #endregion Fetch Proxy File

            try
            {
                using (var sr = new StreamReader(path))
                {
                    var reader = new CsvReader(sr);
                    while (reader.Read())
                    {
                        mProxies.Add(reader.GetRecord <Proxy>());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warn("The proxy list file format is incorrect!");
                Log.Error(ex);
            }
        }
Example #2
0
        public void SaveFirstAttachementTest()
        {
            #region Prepare Data

            const string expectedContent = "Hello World!";
            IEmail       mail163         = new Email163(MAIL_USER_NAME, PASSWORD);
            var          sendMessage     = new MailMessage(MAIL_USER_NAME, MAIL_USER_NAME)
            {
                Subject = "Test Attachement",
                Body    = string.Empty,
            };
            var tempPath1 = Path.GetTempFileName();
            using (var fileStream = new FileStream(tempPath1, FileMode.Create))
            {
                using (var fileWriter = new StreamWriter(fileStream))
                {
                    fileWriter.WriteLine(expectedContent);
                }
            }
            sendMessage.Attachments.Add(new Attachment(tempPath1));
            mail163.Send(sendMessage);

            #endregion Prepare Data

            Thread.Sleep(10 * 1000);

            var resultPath = Path.GetTempFileName();
            mail163.SaveFirstAttachement("Test Attachement", resultPath);

            Assert.IsTrue(File.Exists(resultPath));

            var fileSize = FileHelper.GetFileSize(resultPath);
            Assert.IsTrue(fileSize > 0);

            var resultContent = FileHelper.GetContent(resultPath);
            Assert.AreEqual(expectedContent + "\r\n", resultContent);
        }