示例#1
0
        /// <summary>
        /// Ctor.
        /// </summary>
        public Mailer(string fullPath, IConfiguration configuration = null)
        {
            if (fullPath == null)
            {
                throw new ArgumentNullException(nameof(fullPath));
            }

            Configuration = configuration;

            if (!string.IsNullOrEmpty(_smtpLogin.Value) &&
                !string.IsNullOrEmpty(_smtpPassword.Value))
            {
                _smtp.Value.Credentials = new NetworkCredential(_smtpLogin.Value, _smtpPassword.Value);
            }

            _smtp.Value.EnableSsl = _smtpEnableSsl.Value;

            if (HostingEnvironment.IsHosted)
            {
                fullPath = HostingEnvironment.MapPath(fullPath);
            }

            if (fullPath == null)
            {
                throw new Exception("Email template not found.");
            }

            string template;

            using (var sr = new StreamReader(fullPath, Encoding.UTF8))
            {
                template = sr.ReadToEnd();
            }

            template = template.Replace("charset=utf-8", "charset=iso-8859-2");

            var html = new HtmlDocument();

            html.LoadHtml(template);

            var allImages = new List <EmailImage>();

            var images = html.DocumentNode.SelectNodes("//img");

            if (images != null)
            {
                foreach (var i in images)
                {
                    var src = i.Attributes["src"].Value;

                    // don't add duplicates
                    if (allImages.Any(ix => ix.OriginalNameWithPath.Equals(src, StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    var c = allImages.Count + 1;

                    var it = new EmailImage(Path.Combine(Path.GetDirectoryName(fullPath), src), src, src.Substring(src.LastIndexOf("/", StringComparison.Ordinal) + 1), $"{c}@DROOL");

                    allImages.Add(it);
                }

                template = allImages.Aggregate(template, (current, it) => current.Replace(it.OriginalNameWithPath, $"cid:{it.ImageNameInHtml}"));
            }

            _template = new EmailTemplate(template, allImages);
        }
示例#2
0
        void ReleaseDesignerOutlets()
        {
            if (EmailImage != null)
            {
                EmailImage.Dispose();
                EmailImage = null;
            }

            if (EmailTF != null)
            {
                EmailTF.Dispose();
                EmailTF = null;
            }

            if (FaxusTF != null)
            {
                FaxusTF.Dispose();
                FaxusTF = null;
            }

            if (InternationalCallerTF != null)
            {
                InternationalCallerTF.Dispose();
                InternationalCallerTF = null;
            }

            if (LocationImage != null)
            {
                LocationImage.Dispose();
                LocationImage = null;
            }

            if (PhoneNumberTF != null)
            {
                PhoneNumberTF.Dispose();
                PhoneNumberTF = null;
            }

            if (PostusTF != null)
            {
                PostusTF.Dispose();
                PostusTF = null;
            }

            if (SendDX != null)
            {
                SendDX.Dispose();
                SendDX = null;
            }

            if (TeleImage != null)
            {
                TeleImage.Dispose();
                TeleImage = null;
            }

            if (EmailButton != null)
            {
                EmailButton.Dispose();
                EmailButton = null;
            }
        }