Skip to content

Commit ff98548

Browse files
committed
Improved email templates and moved licence file to root
1 parent da7717b commit ff98548

11 files changed

Lines changed: 366 additions & 67 deletions

File tree

File renamed without changes.
18.4 KB
Loading

OASIS Architecture/NextGenSoftware.OASIS.API.Core/Managers/AvatarManager/AvatarManager-Private.cs

Lines changed: 265 additions & 33 deletions
Large diffs are not rendered by default.
Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
using MailKit.Net.Smtp;
22
using MailKit.Security;
3+
using Microsoft.Extensions.Options;
34
using MimeKit;
45
using MimeKit.Text;
56
using NextGenSoftware.Logging;
67
using NextGenSoftware.OASIS.API.DNA;
78
using NextGenSoftware.OASIS.Common;
9+
using Resend;
10+
using System;
11+
using System.IO;
812
using System.Net;
13+
using System.Net.Http;
914
using System.Net.Mail;
15+
using System.Threading.Tasks;
16+
using static System.Net.WebRequestMethods;
1017
//using System.Net.Mail;
1118

1219
namespace NextGenSoftware.OASIS.API.Core.Managers
1320
{
21+
// Minimal IOptionsSnapshot wrapper
22+
public class OptionsSnapshot<T> : IOptionsSnapshot<T> where T : class
23+
{
24+
public OptionsSnapshot(T value) => Value = value;
25+
public T Value { get; }
26+
public T Get(string? name) => Value;
27+
}
28+
29+
1430
public static class EmailManager
1531
{
1632
private static OASISDNA _OASISDNA;
33+
private static IResend _resend;
34+
35+
public static string LogoBase64 { get; set; }
36+
37+
//static EmailManager()
38+
//{
39+
40+
//}
1741

1842
public static bool IsInitialized
1943
{
@@ -26,6 +50,36 @@ public static bool IsInitialized
2650
public static void Initialize(OASISDNA OASISDNA)
2751
{
2852
_OASISDNA = OASISDNA;
53+
54+
var options = new OptionsSnapshot<ResendClientOptions>(new ResendClientOptions
55+
{
56+
ApiToken = OASISDNA.OASIS.Email.ResendKey
57+
});
58+
59+
var httpClient = new HttpClient();
60+
_resend = new ResendClient(options, httpClient);
61+
62+
try
63+
{
64+
LogoBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", "OASISLogo.jpg")));
65+
}
66+
catch (Exception e)
67+
{
68+
OASISErrorHandling.HandleError($"Error occured in EmailManager.Initialize creating LogoBase64. Reason: {e}");
69+
}
70+
}
71+
72+
public static async Task SendAsync(string to, string subject, string html, string from = null)
73+
{
74+
if (_OASISDNA.OASIS.Email.DisableAllEmails)
75+
return;
76+
77+
var message = new EmailMessage();
78+
message.From = from ?? _OASISDNA.OASIS.Email.EmailFrom;
79+
message.To.Add(to);
80+
message.Subject = subject;
81+
message.HtmlBody = html;
82+
await _resend.EmailSendAsync(message);
2983
}
3084

3185
public static void Send(string to, string subject, string html, string from = null)
@@ -34,7 +88,7 @@ public static void Send(string to, string subject, string html, string from = nu
3488
return;
3589

3690
// For some unknown reason the emails sent from the code below (using mailkit) never arrive, the standard .net code after works! lol ;-)
37-
91+
3892
/*
3993
// create message
4094
var email = new MimeMessage();
@@ -51,28 +105,29 @@ public static void Send(string to, string subject, string html, string from = nu
51105
smtp.Send(email);
52106
smtp.Disconnect(true);*/
53107

54-
MailAddress addressTo = new MailAddress(to);
55-
MailAddress addressFrom = new MailAddress(_OASISDNA.OASIS.Email.SmtpUser);
56108

57-
MailMessage message = new MailMessage(from ?? _OASISDNA.OASIS.Email.EmailFrom, to);
58-
message.IsBodyHtml = true;
59-
message.Subject = subject;
60-
message.Body = html;
109+
//MailAddress addressTo = new MailAddress(to);
110+
//MailAddress addressFrom = new MailAddress(_OASISDNA.OASIS.Email.SmtpUser);
61111

62-
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(_OASISDNA.OASIS.Email.SmtpHost, _OASISDNA.OASIS.Email.SmtpPort)
63-
{
64-
Credentials = new NetworkCredential(_OASISDNA.OASIS.Email.SmtpUser, _OASISDNA.OASIS.Email.SmtpPass),
65-
EnableSsl = true
66-
};
112+
//MailMessage message = new MailMessage(from ?? _OASISDNA.OASIS.Email.EmailFrom, to);
113+
//message.IsBodyHtml = true;
114+
//message.Subject = subject;
115+
//message.Body = html;
67116

68-
try
69-
{
70-
client.Send(message);
71-
}
72-
catch (SmtpException ex)
73-
{
74-
LoggingManager.Log(string.Concat("ERROR Sending Email. Exception: ", ex.ToString()), LogType.Error);
75-
}
117+
//System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(_OASISDNA.OASIS.Email.SmtpHost, _OASISDNA.OASIS.Email.SmtpPort)
118+
//{
119+
// Credentials = new NetworkCredential(_OASISDNA.OASIS.Email.SmtpUser, _OASISDNA.OASIS.Email.SmtpPass),
120+
// EnableSsl = true
121+
//};
122+
123+
//try
124+
//{
125+
// client.Send(message);
126+
//}
127+
//catch (SmtpException ex)
128+
//{
129+
// LoggingManager.Log(string.Concat("ERROR Sending Email. Exception: ", ex.ToString()), LogType.Error);
130+
//}
76131
}
77132
}
78133
}

OASIS Architecture/NextGenSoftware.OASIS.API.Core/NextGenSoftware.OASIS.API.Core.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
3232
</PropertyGroup>
3333

34+
<ItemGroup>
35+
<None Remove="Images\OASISLogo.jpg" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<Content Include="Images\OASISLogo.jpg">
40+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
41+
</Content>
42+
</ItemGroup>
43+
3444
<ItemGroup>
3545
<None Include="..\..\..\..\OneDrive\Dropbox\Our World\Logo\OASISLogo128.jpg">
3646
<Pack>True</Pack>
@@ -46,6 +56,7 @@
4656
<PackageReference Include="NBitcoin" Version="9.0.3" />
4757
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
4858
<PackageReference Include="NLog" Version="4.7.9" />
59+
<PackageReference Include="Resend" Version="0.5.1" />
4960
<PackageReference Include="Rijndael256.Core" Version="3.2.5" />
5061
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
5162
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />

OASIS Architecture/NextGenSoftware.OASIS.API.DNA/OASISDNA.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public class EmailSettings
302302
public int SmtpPort { get; set; }
303303
public string SmtpUser { get; set; }
304304
public string SmtpPass { get; set; }
305+
public string ResendKey { get; set; }
305306
public bool DisableAllEmails { get; set; } //This overrides the SendVerificationEmail setting below. MAKE SURE THIS IS FALSE FOR LIVE!
306307
public bool SendVerificationEmail { get; set; }
307308
public string OASISWebSiteURL { get; set; }

OASIS Architecture/NextGenSoftware.OASIS.OASISBootLoader/OASISBootLoader.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,19 +1328,19 @@ private static OASISResult<OASISDNA> LoadOASISDNA(string OASISDNAPath)
13281328
{
13291329
string dnaPath = Environment.GetEnvironmentVariable("OASIS_DNA_PATH") ?? Path.Combine(AppContext.BaseDirectory, OASISDNAPath);
13301330

1331-
Console.WriteLine($"CurrentDirectory: {Environment.CurrentDirectory}");
1332-
Console.WriteLine($"BaseDirectory: {AppContext.BaseDirectory}");
1333-
Console.WriteLine($"DNA Path being used: {OASISDNAManager.OASISDNAPath}");
1334-
Console.WriteLine($"AppRootDirectory: {AppPathHelper.ResolveAppRootDirectory()}");
1335-
Console.WriteLine($"AppRootDirectory: {AppPathHelper.ResolveAppRootDirectory()}");
1336-
Console.WriteLine($"OASISDNAPath: {OASISDNAPath}");
1337-
Console.WriteLine($"dnaPath: {dnaPath}");
1331+
//Console.WriteLine($"CurrentDirectory: {Environment.CurrentDirectory}");
1332+
//Console.WriteLine($"BaseDirectory: {AppContext.BaseDirectory}");
1333+
//Console.WriteLine($"DNA Path being used: {OASISDNAManager.OASISDNAPath}");
1334+
//Console.WriteLine($"AppRootDirectory: {AppPathHelper.ResolveAppRootDirectory()}");
1335+
//Console.WriteLine($"AppRootDirectory: {AppPathHelper.ResolveAppRootDirectory()}");
1336+
//Console.WriteLine($"OASISDNAPath: {OASISDNAPath}");
1337+
//Console.WriteLine($"dnaPath: {dnaPath}");
13381338

13391339
var dnaResult = OASISDNAManager.LoadDNA(dnaPath);
13401340

1341-
Console.WriteLine($"DNA Load Success: {!dnaResult.IsError}");
1342-
Console.WriteLine($"DNA Load Message: {dnaResult.Message}");
1343-
Console.WriteLine($"OASISDNA null: {OASISDNAManager.OASISDNA == null}");
1341+
//Console.WriteLine($"DNA Load Success: {!dnaResult.IsError}");
1342+
//Console.WriteLine($"DNA Load Message: {dnaResult.Message}");
1343+
//Console.WriteLine($"OASISDNA null: {OASISDNAManager.OASISDNA == null}");
13441344

13451345
return dnaResult;
13461346
//return OASISDNAManager.LoadDNA(OASISDNAPath);

Providers/Blockchain/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<ItemGroup>
4444
<PackageReference Include="eos-sharp" Version="2.2.0" />
4545
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
46-
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.6" />
46+
<!--<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.6" />-->
4747
<PackageReference Include="Nethereum.Signer" Version="4.18.0" />
4848
<!--<PackageReference Include="NLog" Version="4.7.3" />
4949
<PackageReference Include="NLog.Config" Version="4.7.3" />-->

Providers/Cloud/NextGenSoftware.OASIS.API.Providers.GoogleCloudOASIS/NextGenSoftware.OASIS.API.Providers.GoogleCloudOASIS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
30+
<!--<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />-->
3131
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
3232
<PackageReference Include="Google.Cloud.Storage.V1" Version="3.7.0" />
3333
<PackageReference Include="Google.Cloud.Firestore" Version="3.7.0" />

Providers/Network/NextGenSoftware.OASIS.API.Providers.IPFSOASIS/NextGenSoftware.OASIS.API.Providers.IPFSOASIS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<PackageReference Include="Ipfs.Core" Version="0.55.0" />
3131
<PackageReference Include="Ipfs.Engine" Version="0.13.0" />
3232
<PackageReference Include="Ipfs.Http.Client" Version="0.33.0" />
33-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
33+
<!--<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />-->
3434
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
3535
</ItemGroup>
3636

0 commit comments

Comments
 (0)