From 6691c54a476a4a63e05871c5b9ef1610220250fc Mon Sep 17 00:00:00 2001 From: Inestic <50652175+Inestic@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:54:55 +0300 Subject: [PATCH] Added email body option :memo: --- ip2email/ip2email/Actions/ConfigApp.cs | 4 +++ ip2email/ip2email/Actions/SendMail.cs | 12 ++++++++ ip2email/ip2email/Classes/AppConfig.cs | 34 ++++++++++++++++++++++ ip2email/ip2email/Helpers/ConsoleHelper.cs | 4 +++ ip2email/ip2email/Helpers/TextHelper.cs | 10 +++++++ 5 files changed, 64 insertions(+) diff --git a/ip2email/ip2email/Actions/ConfigApp.cs b/ip2email/ip2email/Actions/ConfigApp.cs index 48f5959..1ec1f6d 100644 --- a/ip2email/ip2email/Actions/ConfigApp.cs +++ b/ip2email/ip2email/Actions/ConfigApp.cs @@ -16,6 +16,10 @@ public void Do(string internetIP, List localIPs, ref AppExitCodes appExi appConfig.RecipientEmail = ConsoleHelper.SetOption("Recipient email address . . . : "); appConfig.SenderEmail = ConsoleHelper.SetOption("Sender email address. . . . . : "); appConfig.SenderPassword = ConsoleHelper.SetOption("Sender email password . . . . : "); +<<<<<<< HEAD +======= + appConfig.EmailBody = ConsoleHelper.SetOption("Email body. . . . . . . . . . : "); +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f appConfig.EmailServer = ConsoleHelper.SetOption("Sender SMTP Server (for gmail.com use smtp.gmail.com) . . . : "); appConfig.EmailServerPort = ConsoleHelper.SetOption("Sender SMTP Port (for gmail.com use 587). . . . . . . . . . : "); ConsoleHelper.EmailSettingsSave(true); diff --git a/ip2email/ip2email/Actions/SendMail.cs b/ip2email/ip2email/Actions/SendMail.cs index 4c102b1..c4843fe 100644 --- a/ip2email/ip2email/Actions/SendMail.cs +++ b/ip2email/ip2email/Actions/SendMail.cs @@ -9,13 +9,21 @@ namespace IP2Email.Classes { internal class SendMail : IArgsAction { +<<<<<<< HEAD private void SendByEmail(AppConfig config, string ip) +======= + private void SendEmail(AppConfig config, string ip) +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f { MailMessage message = new MailMessage(from: new MailAddress(config.SenderEmail, TextHelper.SenderDisplayName), to: new MailAddress(config.RecipientEmail)) { Subject = TextHelper.EmailSubject, +<<<<<<< HEAD Body = $"{TextHelper.EmailBody}: {ip}", +======= + Body = $"{TextHelper.EmailBody}: {ip}. {config.EmailBody}", +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f IsBodyHtml = false }; @@ -36,7 +44,11 @@ public void Do(string internetIP, List localIPs, ref AppExitCodes appExi { try { +<<<<<<< HEAD SendByEmail(appConfig, internetIP); +======= + SendEmail(appConfig, internetIP); +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f ConsoleHelper.EmailSend(senderEmail: appConfig.SenderEmail, recipientEmail: appConfig.RecipientEmail); } catch (Exception ex) diff --git a/ip2email/ip2email/Classes/AppConfig.cs b/ip2email/ip2email/Classes/AppConfig.cs index 035b373..d5d9523 100644 --- a/ip2email/ip2email/Classes/AppConfig.cs +++ b/ip2email/ip2email/Classes/AppConfig.cs @@ -13,6 +13,10 @@ internal AppConfig() SetIsConfiguredState(); } +<<<<<<< HEAD +======= + internal string EmailBody { get => DecodeFromRegistry("EBO"); set => EncodeToRegistry("EBO", value); } +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f internal string EmailServer { get => DecodeFromRegistry("ESE"); set => EncodeToRegistry("ESE", value); } internal string EmailServerPort { get => DecodeFromRegistry("ESP"); set => EncodeToRegistry("ESP", value); } internal bool IsConfigured { get; set; } @@ -23,6 +27,7 @@ internal AppConfig() private string DecodeFromRegistry(string regKeyName) { string plaintext = null; +<<<<<<< HEAD try { @@ -48,15 +53,38 @@ private string DecodeFromRegistry(string regKeyName) { plaintext = srDecrypt.ReadToEnd(); } +======= + byte[] regKeyValue = Registry.CurrentUser.OpenSubKey(TextHelper.RegistryAppPath)?.GetValue(regKeyName) as byte[]; + + if (regKeyValue != null) + { + using (Aes aes = Aes.Create()) + { + aes.Key = Encoding.UTF8.GetBytes(TextHelper.SecurityKey); + aes.IV = Encoding.UTF8.GetBytes(TextHelper.SecurityKey); + + ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); + + using (MemoryStream msDecrypt = new MemoryStream(regKeyValue)) + { + using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) + { + using (StreamReader srDecrypt = new StreamReader(csDecrypt)) + { + plaintext = srDecrypt.ReadToEnd(); +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f } } } } } +<<<<<<< HEAD catch { return null; } +======= +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f return plaintext; } @@ -81,9 +109,15 @@ private void EncodeToRegistry(string regKeyName, string regKeyValue) } Registry.CurrentUser.OpenSubKey(TextHelper.RegistryKeySoftware, true) +<<<<<<< HEAD .CreateSubKey(TextHelper.RegistryKeyAuthor, true) .CreateSubKey(TextHelper.RegistryAppName, true) .SetValue(regKeyName, msEncrypt.ToArray()); +======= + .CreateSubKey(TextHelper.RegistryKeyAuthor, true) + .CreateSubKey(TextHelper.RegistryAppName, true) + .SetValue(regKeyName, msEncrypt.ToArray()); +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f } } } diff --git a/ip2email/ip2email/Helpers/ConsoleHelper.cs b/ip2email/ip2email/Helpers/ConsoleHelper.cs index a8fb850..126c003 100644 --- a/ip2email/ip2email/Helpers/ConsoleHelper.cs +++ b/ip2email/ip2email/Helpers/ConsoleHelper.cs @@ -46,7 +46,11 @@ internal static void ShowAppBanner() Console.WriteLine(); Console.WriteLine("IP2Email sends an email with your public IP address got by https://ifconfig.me"); Console.WriteLine("Copyright (C) 2020 — 2021, Inestic"); +<<<<<<< HEAD Console.WriteLine("https://github.com/inestic/ip2email"); +======= + Console.WriteLine("https://github.com/Inestic/ip2email"); +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f Console.WriteLine(); } diff --git a/ip2email/ip2email/Helpers/TextHelper.cs b/ip2email/ip2email/Helpers/TextHelper.cs index 7c5d8be..08f1b30 100644 --- a/ip2email/ip2email/Helpers/TextHelper.cs +++ b/ip2email/ip2email/Helpers/TextHelper.cs @@ -10,9 +10,19 @@ internal static class TextHelper internal static readonly string FailedGetLocalIP = "Failed to obtain local IP address"; internal static readonly string InternetIpSite = "https://ifconfig.me/ip"; internal static readonly string RegistryAppName = "IP2Email"; +<<<<<<< HEAD internal static readonly string RegistryKeyAuthor = "Inestic"; internal static readonly string RegistryKeySoftware = "Software"; internal static readonly string SecurityKey = ""; internal static readonly string SenderDisplayName = "IP2Email"; } } +======= + internal static readonly string RegistryAppPath = $@"{RegistryKeySoftware}\{RegistryKeyAuthor}\{RegistryAppName}"; + internal static readonly string RegistryKeyAuthor = "Inestic"; + internal static readonly string RegistryKeySoftware = "Software"; + internal static readonly string SecurityKey = "1234567812345678"; + internal static readonly string SenderDisplayName = "IP2Email"; + } +} +>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f