forked from ddrilling/AsbCloudServer
Add verified SendMail example
This commit is contained in:
parent
1f1f86f00e
commit
ae8b549617
@ -6,6 +6,12 @@
|
||||
<StartupObject>ConsoleApp1.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Connected Services\**" />
|
||||
<EmbeddedResource Remove="Connected Services\**" />
|
||||
<None Remove="Connected Services\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
|
||||
<PackageReference Include="Google.Apis.Drive.v3" Version="1.55.0.2502" />
|
||||
@ -20,11 +26,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AsbCloudApp\AsbCloudApp.csproj" />
|
||||
<ProjectReference Include="..\AsbCloudDb\AsbCloudDb.csproj" />
|
||||
|
@ -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();
|
||||
|
||||
|
29
ConsoleApp1/SendMail.cs
Normal file
29
ConsoleApp1/SendMail.cs
Normal file
@ -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 = "<html><boby><H1>this is a test text</H1></boby></html>";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user