public static IMail MakeMail(EmailItem email, TemplateItem template, string from) { var body = template.Make(email.Value); IFluentMail mail; if (template.IsHtml) { mail = Mail.Html(""); var matches = Regex.Matches(body, @"<img[^<>]+src=""?([^""\s<>]+)", RegexOptions.IgnoreCase); for (int i = 0, length = matches.Count; i < length; i++) { var file = matches[i].Groups[1].Value; if (file.IndexOf("//") >= 0 || !File.Exists(file)) { continue; } body = body.Replace(file, "cid:img" + i); mail.AddVisual(file).SetContentId("img" + i); } mail.Html(body); } else { mail = Mail.Text(body); } foreach (var file in template.Attachment) { mail.AddAttachment(file).SetFileName(Path.GetFileName(file)); } return(mail.To(email.Email) .From(from) .Subject(template.Title) .Create()); }