ASCU_ALL/Mailing/Program.cs
2020-09-04 12:49:15 +05:00

92 lines
2.2 KiB
C#

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.");
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 file = Directory.GetCurrentDirectory() + "/" + time.ToString("yyyy-MM-dd") + ".pdf";
foreach (var e in mailList)
Mailing.SendMail(new MailAddress(e), file);
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);
}
}
}