Ejemplo n.º 1
0
 public void EmailService(forgetclass link)
 {
     try
     {
         string HtmlBody;
         using (StreamReader streamReader = new StreamReader(config["IssuerEmailDetail:HtmlBodyFile"], Encoding.UTF8))
         {
             HtmlBody = streamReader.ReadToEnd();
         }
         HtmlBody = HtmlBody.Replace("JwtToken", link.JwtToken);
         MailMessage message = new MailMessage();
         SmtpClient  smtp    = new SmtpClient();
         message.From = new MailAddress(config["IssuerEmailDetail:Email"]);
         message.To.Add(new MailAddress(link.Email));
         message.Subject            = "Reset Password";
         message.IsBodyHtml         = true;
         message.Body               = HtmlBody;
         smtp.Port                  = 587;
         smtp.Host                  = "smtp.gmail.com";
         smtp.EnableSsl             = true;
         smtp.UseDefaultCredentials = false;
         smtp.Credentials           = new NetworkCredential(config["IssuerEmailDetail:Email"], config["IssuerEmailDetail:Password"]);
         smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
         smtp.Send(message);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 2
0
        public void ReplaceEmbeddedImages(ILogger log = null)
        {
            log = log ?? new NullLogger();

            try
            {
                var attchments = Attachments.Where(a => a.isEmbedded && !string.IsNullOrEmpty(a.storedFileUrl)).ToList();

                if (!attchments.Any())
                {
                    return;
                }

                foreach (var attach in attchments)
                {
                    if (!string.IsNullOrEmpty(attach.contentId))
                    {
                        HtmlBody = HtmlBody.Replace(string.Format("cid:{0}", attach.contentId.Trim('<').Trim('>')),
                                                    attach.storedFileUrl);
                    }
                    else if (!string.IsNullOrEmpty(attach.contentLocation))
                    {
                        HtmlBody = HtmlBody.Replace(string.Format("{0}", attach.contentLocation),
                                                    attach.storedFileUrl);
                    }
                    else
                    {
                        //This attachment is not embedded;
                        attach.contentId       = null;
                        attach.contentLocation = null;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("ReplaceEmbeddedImages() \r\n Exception: \r\n{0}\r\n", ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public void ReplaceEmbeddedImages(ILogger log = null)
        {
            log = log ?? new NullLogger();

            try
            {
                var attchments = Attachments.Where(a => a.isEmbedded && !string.IsNullOrEmpty(a.storedFileUrl)).ToList();

                if (!attchments.Any())
                {
                    return;
                }

                if (HtmlBodyStream.Length > 0)
                {
                    HtmlBodyStream.Seek(0, SeekOrigin.Begin);

                    var doc = new HtmlDocument();
                    doc.Load(HtmlBodyStream, Encoding.UTF8);

                    var hasChanges = false;

                    foreach (var attach in attchments)
                    {
                        HtmlNodeCollection oldNodes = null;

                        if (!string.IsNullOrEmpty(attach.contentId))
                        {
                            oldNodes =
                                doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'cid:" +
                                                             attach.contentId.Trim('<').Trim('>') + "'))]");
                        }

                        if (!string.IsNullOrEmpty(attach.contentLocation) && oldNodes == null)
                        {
                            oldNodes =
                                doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'" +
                                                             attach.contentLocation + "'))]");
                        }

                        if (oldNodes == null)
                        {
                            //This attachment is not embedded;
                            attach.contentId       = null;
                            attach.contentLocation = null;
                            continue;
                        }

                        foreach (var node in oldNodes)
                        {
                            node.SetAttributeValue("src", attach.storedFileUrl);
                            hasChanges = true;
                        }
                    }

                    HtmlBodyStream.Seek(0, SeekOrigin.Begin);

                    if (!hasChanges)
                    {
                        return;
                    }

                    HtmlBodyStream.Close();
                    HtmlBodyStream.Dispose();

                    HtmlBodyStream = new MemoryStream();

                    using (var sw = new StreamWriter(HtmlBodyStream, Encoding.UTF8, 1024, true))
                    {
                        doc.DocumentNode.WriteTo(sw);
                        sw.Flush();
                        HtmlBodyStream.Seek(0, SeekOrigin.Begin);
                    }

                    HtmlBodyStream.Seek(0, SeekOrigin.Begin);
                }
                else
                {
                    foreach (var attach in attchments)
                    {
                        if (!string.IsNullOrEmpty(attach.contentId))
                        {
                            HtmlBody = HtmlBody.Replace(string.Format("cid:{0}", attach.contentId.Trim('<').Trim('>')),
                                                        attach.storedFileUrl);
                        }
                        else if (!string.IsNullOrEmpty(attach.contentLocation))
                        {
                            HtmlBody = HtmlBody.Replace(string.Format("{0}", attach.contentLocation),
                                                        attach.storedFileUrl);
                        }
                        else
                        {
                            //This attachment is not embedded;
                            attach.contentId       = null;
                            attach.contentLocation = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("ReplaceEmbeddedImages() \r\n Exception: \r\n{0}\r\n", ex.ToString());
            }
        }