From ae8b549617692cc366c9ca320fbfb3658ceb071f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 17 Jan 2022 17:55:00 +0500 Subject: [PATCH] Add verified SendMail example --- ConsoleApp1/ConsoleApp1.csproj | 11 ++++++----- ConsoleApp1/Program.cs | 22 +++------------------- ConsoleApp1/SendMail.cs | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 ConsoleApp1/SendMail.cs diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj index f69936a4..1b11ff58 100644 --- a/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -6,6 +6,12 @@ ConsoleApp1.Program + + + + + + @@ -20,11 +26,6 @@ - - - - - diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index 65203455..1f653d09 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -7,6 +7,7 @@ using AsbCloudDb.Model; using AsbCloudDb; using Google.Apis.Drive.v3.Data; using Microsoft.EntityFrameworkCore; +using System.Net.Mail; namespace ConsoleApp1 { @@ -17,27 +18,10 @@ namespace ConsoleApp1 class Program { - private static double AssumeTimezoneOffset(DateTime nearToCurrentDate) - { - var offset = 5d; - if (nearToCurrentDate.Kind == DateTimeKind.Unspecified) - { - var now = DateTime.UtcNow; - var minutes = 60 * (now.Hour - nearToCurrentDate.Hour) + now.Minute - nearToCurrentDate.Minute; - var minutesPositive = (1440_0000 + minutes) % 1440; //60*24 - var halfsHours = Math.Round(1d * minutesPositive / 30d); // quarters are ignored - var hours = halfsHours / 2; - offset = hours < 12 ? hours : 24 - hours ; - } - if (nearToCurrentDate.Kind == DateTimeKind.Local) - offset = TimeZoneInfo.Local.BaseUtcOffset.TotalHours; - - return offset; - } - static void Main(/*string[] args*/) { - var o = AssumeTimezoneOffset(new DateTime(2022, 01, 10, 15, 40, 00)); + SendMail.Main(); + //DbDemoDataService.AddDemoData(); //.GetAwaiter().GetResult(); diff --git a/ConsoleApp1/SendMail.cs b/ConsoleApp1/SendMail.cs new file mode 100644 index 00000000..d3607bb7 --- /dev/null +++ b/ConsoleApp1/SendMail.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + public static class SendMail + { + public static void Main() + { + MailAddress to = new MailAddress("ng.frolov@autodrilling.ru"); + MailAddress from = new MailAddress("bot@autodrilling.ru"); + MailMessage message = new MailMessage(from, to); + message.Subject = "Using the new SMTP client."; + message.Body = "

this is a test text

"; + message.IsBodyHtml = true; + + SmtpClient client = new SmtpClient("smtp.timeweb.ru"); + client.EnableSsl = true; + client.UseDefaultCredentials = false; + client.Credentials = new System.Net.NetworkCredential("bot@autodrilling.ru", "xHhgwZ4D"); + + client.Send(message); + } + } +}