Skip to content

Commit

Permalink
Added email body option 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
Inestic committed Oct 15, 2021
1 parent 9e0b2e2 commit 6691c54
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ip2email/ip2email/Actions/ConfigApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public void Do(string internetIP, List<string> 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);
Expand Down
12 changes: 12 additions & 0 deletions ip2email/ip2email/Actions/SendMail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -36,7 +44,11 @@ public void Do(string internetIP, List<string> localIPs, ref AppExitCodes appExi
{
try
{
<<<<<<< HEAD
SendByEmail(appConfig, internetIP);
=======
SendEmail(appConfig, internetIP);
>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f
ConsoleHelper.EmailSend(senderEmail: appConfig.SenderEmail, recipientEmail: appConfig.RecipientEmail);
}
catch (Exception ex)
Expand Down
34 changes: 34 additions & 0 deletions ip2email/ip2email/Classes/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -23,6 +27,7 @@ internal AppConfig()
private string DecodeFromRegistry(string regKeyName)
{
string plaintext = null;
<<<<<<< HEAD

try
{
Expand All @@ -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;
}
Expand All @@ -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
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions ip2email/ip2email/Helpers/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 10 additions & 0 deletions ip2email/ip2email/Helpers/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6691c54

Please sign in to comment.