{
string regexImgSrc = @"]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
MatchCollection matchesImgSrc = Regex.Matches(htmlBody, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
foreach (Match m in matchesImgSrc)
{
string src_url = m.Groups[1].Value;
string pathOfFile = System.Web.HttpContext.Current.Server.MapPath(HttpUtility.UrlDecode(src_url));
var splitPaths = pathOfFile.Split('.');
string extention_file = splitPaths[splitPaths.Length - 1].ToLower();
LinkedResource inline = null;
switch (extention_file)
{
case "gif":
{
inline = new LinkedResource(pathOfFile, MediaTypeNames.Image.Gif);
break;
}
case "png":
{
inline = new LinkedResource(pathOfFile, "image/png");
break;
}
default:
inline = new LinkedResource(pathOfFile, MediaTypeNames.Image.Jpeg);
break;
}
inline.ContentId = Guid.NewGuid().ToString();
htmlBody = htmlBody.Replace(src_url, "cid:" + inline.ContentId);
AlternateView avHtml = AlternateView.CreateAlternateViewFromString
(htmlBody, null, MediaTypeNames.Text.Html);
avHtml.LinkedResources.Add(inline);
mail.AlternateViews.Add(avHtml);
Attachment att = new Attachment(pathOfFile);
att.ContentDisposition.Inline = true;
mail.Attachments.Add(att);
}
return mail;
}
public void sendMail(string htmlBody, string toMail)
{
SmtpClient client = new SmtpClient();
client.Port = int.Parse(this.GetValue("SmtpPort", listVariables));
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("username", "passwrd");
client.Host = this.GetValue("SmtpServer", listVariables);
MailMessage mail = new MailMessage();
mail.From = new MailAddress("frommail");
mail.To.Add(toMail);
mail.Subject = "subject title";
mail.IsBodyHtml = true;
mail = makeupDataForSendMail(htmlBody, mail);
client.Send(mail);
}
Now you can call: sendMail(