hi i am trying to send mail from asp.net by embedding images its coming fine in gmail account but in yahoo and out look its not coming i am receving the mail but no content inside the mAIL
if i dont write this line
AlternateView avImages = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
mail.AlternateViews.Add(htmlView);//body of the mail
resources.ForEach(x => avImages.LinkedResources.Add(x));//add all the linked resources in alternative View
mail.AlternateViews.Add(avImages);// Add the views for image
and simply add
mail.body = EmailContent;
then the mail comes in the yahoo ,outlook and gmail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
SmtpClient smtp = new SmtpClient();
if (fup1.HasFile)
{
mail.Attachments.Add(new Attachment(fup1.PostedFile.InputStream, fup1.FileName));
}
mail.To.Add(new MailAddress(ds.Tables[0].Rows[i]["Email"].ToString()));
mail.From = new MailAddress(ddlpromoemail.SelectedItem.Text.ToString().Trim());
mail.Subject = txtsubjectline.Text;
mail.IsBodyHtml = true;
string docid = ds.Tables[0].Rows[i]["EmployeeCode"].ToString();
ViewState["storeContent"] = EmailContent;
Regex reg = new Regex(@"s]+))?)+\s*|\s*)/?>");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("", null, "text/html");
List<LinkedResource> resources = new List<LinkedResource>();
foreach (Match match in reg.Matches(EmailContent))
{
string path = SaveImage(match.Value,ref err);
LinkedResource LinkedImage = new LinkedResource(@path);
string height = Regex.Match(match.Value, "<img.+?height=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
string width = Regex.Match(match.Value, "<img.+?width=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
LinkedImage.ContentType = new ContentType(MediaTypeNames.Image.Jpeg);
LinkedImage.ContentId = imgn + "MyPic";
string imgtag = "<img height='" + height + "' width='" + width + "' src=cid:" + imgn + "MyPic" + " />";
EmailContent = EmailContent.Replace(match.Value, imgtag);
resources.Add(LinkedImage);
imgn++;
}
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
CultureInfo ci = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentCulture = ci;
string url ="http://localhost:54645/View/MarketingEngine/beacon.aspx?email=" + ds.Tables[0].Rows[i]["Email"].ToString() + "&empcode=" + ds.Tables[0].Rows[i]["EmployeeCode"].ToString() + "&template=" + txtpromoemailname.Text + "&Dateins=" + DateTime.Now.ToString("dd-MMM-yyyy", ci);
string bgimg = "<img height="2" width="2">.*?)(""|').*?>(?<value>.*?)");
foreach (Match match in r.Matches(EmailContent))
{
string href = match.Groups["href"].Value.ToString().Trim();
string link_url = "http://localhost:54645/View/MarketingEngine/LinksClicked.aspx?email=" + ds.Tables[0].Rows[i]["Email"].ToString() + "&address=" + href + "&empcode=" + ds.Tables[0].Rows[i]["EmployeeCode"].ToString() + "&template=" + txtpromoemailname.Text + "&Dateins=" + DateTime.Now.ToString("dd-MMM-yyyy", ci);
EmailContent = EmailContent.Replace(href, link_url);
}
string html = "<!DOCTYPE html><html><body>" + EmailContent +"</body></html>";
AlternateView avImages = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
mail.AlternateViews.Add(htmlView);
resources.ForEach(x => avImages.LinkedResources.Add(x));
mail.AlternateViews.Add(avImages);
smtp.Host = host;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(ddlpromoemail.SelectedItem.Text.ToString().Trim(),password);
smtp.EnableSsl = true;
mail.Headers.Add("Disposition-Notification-To", "<" + ddlBounceEmailid.SelectedItem.Text.ToString().Trim() + ">");
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
smtp.Send(mail);