活动页面添加参赛作品瀑布流
[PumpkinHouse.git] / Email / Program.cs
blob452b82138f6dc865b29d7519a3a29f502709ad20
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using PumpkinHouse.Utils;
6 using Mail;
7 using PumpkinHouseDatabase;
8 using System.Net.Mail;
9 using System.Threading;
11 namespace Email
13 class Program
15 private static void PrintHelp()
17 Console.WriteLine("usage: SendEmail.exe [/reset] [<邮件主题> <模板路径>]");
20 private static void ResetRecords()
22 using (DataUtils utils = new DataUtils())
24 foreach (var u in utils.FindAllUsers().ToList())
26 u.Email_Sent = 0;
28 utils.Commit();
32 private static void SendEmail(string subject, string template, bool test)
34 if (test)
36 Console.WriteLine("Test Mode");
38 MailClient.LoadConfiguration("mail.config");
39 // EmailHelper.SendActivityEmail(subject, "728635054@qq.com", template, new string[] { "测试邮件" });
40 using (DataUtils utils = new DataUtils())
42 bool start = true;
43 var result = utils.FindAllUsers().Where(u => u.Receive_Email == 1 && u.Email != "" && u.Email_Verified != 2 && u.Email_Sent != 1).ToList();
45 foreach (var r in result)
47 //if (r.Email == "iujijvjn@126.com")
48 //{
49 // //start = true;
50 //}
51 if (!start) { Console.WriteLine("\tskip"); continue; }
53 bool retry;
56 retry = false;
57 try
59 SendEmail(subject, template, utils, r, test);
61 catch (Exception e)
63 Console.WriteLine(r.Email + "\t" + r.Nick_Name + "\t" + e.Message);
64 if (e.Message.Equals("Mailbox unavailable. The server response was: Connection frequency limited"))
66 Thread.Sleep(1000 * 60 * 10); // 停止发送10分钟
67 Console.WriteLine(r.Email + "\t" + r.Nick_Name + "\tRetrying");
68 retry = true;
71 } while (retry);
72 if (!test)
74 Thread.Sleep(25000);
80 private static void SendEmail(string subject, string template, DataUtils utils, DB_User r, bool test)
82 if (r.Email == "raymanyoung@gmail.com" || !test)
84 EmailHelper.SendActivityEmail(subject, r.Email, template, new string[] { r.Nick_Name });
85 r.Email_Sent = 1;
86 utils.Commit();
87 Console.WriteLine(r.Email + "\t" + r.Nick_Name + "\tSuccess");
91 static void Main(string[] args)
93 if (args.Length < 1 || args.Length > 3)
95 PrintHelp();
96 return;
99 DataUtils.ConnectionString = @"Server=localhost\SQLExpress;Database=MutouheziDatabase;Integrated Security=true"; //305906536
101 if (args.Length == 1)
103 if (args[0].Equals("/reset", StringComparison.OrdinalIgnoreCase))
105 ResetRecords();
106 return;
108 else
110 PrintHelp();
111 return;
115 if (args.Length == 3)
117 if (args[2].Equals("/prod", StringComparison.OrdinalIgnoreCase))
119 SendEmail(args[0], args[1], false);
121 else
123 PrintHelp();
124 return;
127 if (args.Length == 2)
129 SendEmail(args[0], args[1], true);