ASCU_ALL/Mailing/Program.cs
Georgy Khatuncev 845afe8e75 Clear Binaries
Clear binaries and start create logger
2020-11-17 15:44:19 +05:00

154 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DataClients;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
namespace Mailing
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Need params.");
return;
}
var mailList = new List<string>();
{
var strings = File.ReadAllLines(args.Last());
foreach (var e in strings)
{
var tmp = e.Split(' ');
foreach (var ee in tmp)
{
try
{
MailAddress m = new MailAddress(ee.ToLower());
if (!mailList.Contains(ee.ToLower()))
mailList.Add(ee.ToLower());
}
catch (Exception) { }
}
}
}
switch (args[0])
{
case "SZO":
if (args.Length != 3)
{
Console.WriteLine("Wrong format");
Console.WriteLine("Example: Maling SZO 2020.07.14 /mail.list");
return;
}
var time = DateTime.Now;
{
try
{
var s = args[1].Split('.');
time = new DateTime(
Convert.ToInt32(s[0]),
Convert.ToInt32(s[1]),
Convert.ToInt32(s[2]));
}
catch
{
Console.WriteLine("Wrong format data");
Console.WriteLine("Example: 2020.07.14");
return;
}
}
GenSZO.GetPDF(time);
var fileszo = Directory.GetCurrentDirectory() + "/SZO/" + time.ToString("yyyy-MM-dd") + ".pdf";
foreach (var e in mailList)
Mailing.SendMail(new MailAddress(e), fileszo);
break;
case "NTC1":
if (args.Length != 4)
{
Console.WriteLine("Wrong format");
Console.WriteLine("Example: Maling NTC1 2020.07.07 2020.07.14 /mail.list");
return;
}
var timestart = DateTime.Now.AddDays(-7);
var timeend = DateTime.Now;
{
try
{
var s = args[1].Split('.');
timestart = new DateTime(
Convert.ToInt32(s[0]),
Convert.ToInt32(s[1]),
Convert.ToInt32(s[2]));
s = args[2].Split('.');
timeend = new DateTime(
Convert.ToInt32(s[0]),
Convert.ToInt32(s[1]),
Convert.ToInt32(s[2]));
}
catch
{
Console.WriteLine("Wrong format data");
Console.WriteLine("Example: 2020.07.14");
return;
}
}
GenNTC1.GetNTC1(timestart, timeend);
var filentc1 = Directory.GetCurrentDirectory() + "/NTC1/" + timestart.ToString(@"yyyyMMdd") + "-" + timeend.ToString(@"yyyyMMdd") + ".txt";
foreach (var e in mailList)
Mailing.SendMailNTC1(new MailAddress(e), filentc1);
break;
}
}
}
public static class Mailing
{
private static readonly MailAddress From = new MailAddress("no-reply@vsmpo.ru", "ASCKU_32_ROBOT");
private static SmtpClient Smtp = new SmtpClient("mail.vsmpo.ru", 25);
private static string Subject = "Контроль работы SZO";
private static string Body = "Ежедневная рассылка контроля работы " +
"водокольцевых насосов SZO на ВДП в цехе №32";
public static void SendMail(MailAddress to, string file)
{
MailMessage m = new MailMessage(From, to)
{
Subject = Subject,
Body = Body
};
m.Attachments.Add(new Attachment(file));
Smtp.Send(m);
}
public static void SendMailNTC1(MailAddress to, string file)
{
MailMessage m = new MailMessage(From, to)
{
Subject = "Список плавок с низской скоростью штока",
Body = "Еженедельная рассылка списка плавок " +
"с низкой скоростью штока."
};
try
{
m.Attachments.Add(new Attachment(file));
}
catch
{
m.Body = m.Body + "\n В заданный период времени не было найдено подходящих плавок.";
Console.WriteLine("Отсутствует файл для отправки.");
}
finally
{
Smtp.Send(m);
}
}
}
}