Example #1
0
        public static void Check()
        {
            var emailContentManager = new EmailContentManager();

            emailContentManager.LoadEmailFile();
            if (emailContentManager.Content.Count < 1)
            {
                const string msg = "Email content could not be loaded. Emails will not be sent";
                _log.Error(msg);
                Console.WriteLine(msg);
            }
            else
            {
                var msg = $"Email content loaded successfully with {emailContentManager.Content.Count} records found";
                _log.Info(msg);
                Console.WriteLine(msg);
            }
        }
Example #2
0
        public EmailConfiguration(IList <object> args)
        {
            var settings         = Program.Configuration.Email;
            var emailConfigArray = args;

            if (emailConfigArray.Count != 8)
            {
                throw new Exception(
                          $"Incorrect number of email config array items - got {emailConfigArray.Count}, expected 8");
            }

            this.Id          = Guid.NewGuid();
            this.To          = new List <string>();
            this.Cc          = new List <string>();
            this.Bcc         = new List <string>();
            this.Attachments = new List <string>();

            this.From = emailConfigArray[0].ToString();

            // just use the first account we find already registered in outlook
            //if (this.From.Equals("CurrentUser", StringComparison.CurrentCultureIgnoreCase))
            //{
            //    this.From = $"{Environment.UserName}@{System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName}";
            //}

            this.To  = ParseEmail(emailConfigArray[1].ToString(), settings.RecipientsToMin, settings.RecipientsToMax);
            this.Cc  = ParseEmail(emailConfigArray[2].ToString(), settings.RecipientsCcMin, settings.RecipientsCcMax);
            this.Bcc = ParseEmail(emailConfigArray[3].ToString(), settings.RecipientsBccMin, settings.RecipientsBccMax);

            var emailContent = new EmailContentManager();

            this.Subject = emailConfigArray[4].ToString();

            if (this.Subject.Equals("random", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Subject = emailContent.Subject;
            }

            this.Body = emailConfigArray[5].ToString();
            if (this.Body.Equals("random", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Body = emailContent.Body;

                this.Body +=
                    $"{Environment.NewLine}{Environment.NewLine}CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, may contain information that is protected by the DoD Privacy Act. This e-mail transmission is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that you are not authorized to read, print, retain, copy, disclose, distribute, or use this message, any part of it, or any attachments. If you have received this message in error, please immediately notify the sender by telephone or return e-mail and delete this message and any attachments from your system without reading or saving in any manner. You can obtain additional information about the DoD Privacy Act at http://dpclo.defense.gov/privacy. Thank you.{Environment.NewLine}Timestamp: {DateTime.Now} ID: {this.Id}";
            }

            this.BodyType = EmailBodyType.PlainText;


            if (!string.IsNullOrEmpty(emailConfigArray[6].ToString()))
            {
                emailConfigArray[6] = emailConfigArray[6].ToString().Trim();
                if (emailConfigArray[6].ToString().Equals("HTML", StringComparison.InvariantCultureIgnoreCase))
                {
                    this.BodyType = EmailBodyType.HTML;
                }
                else if (emailConfigArray[6].ToString().Equals("RTF", StringComparison.InvariantCultureIgnoreCase))
                {
                    this.BodyType = EmailBodyType.RTF;
                }
            }

            if (!string.IsNullOrEmpty(emailConfigArray[7].ToString()))
            {
                var a = emailConfigArray[7].ToString().Split(Convert.ToChar(","));
                foreach (var o in a)
                {
                    if (File.Exists(o))
                    {
                        this.Attachments.Add(o);
                    }
                    else
                    {
                        _log.Debug($"Can't add attachment {o} - file was not found");
                    }
                }
            }
        }