Beispiel #1
0
        // Get a valued stored in the appsettings.
        // Pass in a key like TestArea:TestKey to get TestValue
        public static SettingsConfigHelper GetCurrentSettings(string Key)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);


            IConfigurationRoot configuration = builder.Build();

            var settings = new SettingsConfigHelper(configuration.GetSection("EmailSender"), Key);

            return(settings);
        }
Beispiel #2
0
        public static void sendEmailFromAWS(string body, string subject, string toEmail, string ccEmail = "")
        {
            var Host      = SettingsConfigHelper.GetCurrentSettings("Host").appSettingValue;
            var FromEmail = SettingsConfigHelper.GetCurrentSettings("Email").appSettingValue;
            var UserName  = SettingsConfigHelper.GetCurrentSettings("UserName").appSettingValue;
            var Password  = SettingsConfigHelper.GetCurrentSettings("Password").appSettingValue;
            var Port      = int.Parse(SettingsConfigHelper.GetCurrentSettings("Port").appSettingValue);

            try
            {
                MailMessage message = new MailMessage();
                message.IsBodyHtml = true;
                message.From       = new MailAddress(FromEmail);
                message.To.Add(new MailAddress(toEmail));
                if (!string.IsNullOrEmpty(ccEmail))
                {
                    string[] ccid = ccEmail.Split(',');
                    foreach (var item in ccid)
                    {
                        message.CC.Add(new MailAddress(item));
                    }
                }
                message.Subject = subject;
                message.Body    = body;

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Host           = Host; // These are the host connection properties
                client.Port           = Port;
                client.EnableSsl      = true;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Credentials    = new System.Net.NetworkCredential(UserName, Password); // here you need to declare the credentials of the sender
                try
                {
                    client.Send(message);      // And finally this is the line which executes our process and sends mail
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #3
0
 public static string AppSetting(string Key)
 {
     _appSettings = GetCurrentSettings(Key);
     return(_appSettings.appSettingValue);
 }