i have just created one newsletter application that send html enabled and image embedded mail to large no of subscribers. i have some small problem with received mail to my gmail account. can't get full html mail to read. here is my code :
private static void SendEmail(string fromName, string fromEmailAddress, string emailpassword, string smtphost, int smtpport, bool enableSSL, string toEmailAddress, string subject, string plainText, List<string> file_names, int templateID, bool IsUnsubscriptionLink, SmtpClient client)
{
MailMessage msg = new MailMessage();
if (fromName != null)
msg.From = new MailAddress(fromName + " <" + fromEmailAddress + ">");
else
msg.From = new MailAddress(fromEmailAddress);
msg.To.Add(new MailAddress(toEmailAddress));
msg.Subject = subject;
msg.IsBodyHtml = true;
client.Host = smtphost;
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential(fromEmailAddress, emailpassword);
client.Port = smtpport;
client.EnableSsl = enableSSL;
client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
msg.Priority = MailPriority.High;
msg.Subject = subject;
string rbody = ConvertAllString(plainText, templateID);
string fbody = rbody.Replace("\"", "'");
if (fbody.Contains("src='cid:"))
{
var htmlView = AlternateView.CreateAlternateViewFromString(msg.Body, null, "text/html");
do
{
int src = fbody.IndexOf("src='cid:");
if (src != -1)
{
fbody = fbody.Remove(0, src + 9);
var dot = Regex.Match(fbody, @"\.(jpg|jpeg|gif|png)");
if (dot.Success)
{
int comma = fbody.IndexOf("'");
if (comma != -1)
{
if (!string.IsNullOrEmpty(fbody.Substring(0, comma)))
{
string imageSource = Path.Combine(HttpRuntime.AppDomainAppPath, "EmailImages\\", fbody.Substring(0, comma));
var leftImageLink = (dynamic)null;
switch (Path.GetExtension(imageSource).ToLower())
{
case ".jpg":
leftImageLink = new LinkedResource(imageSource, "image/jpg")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".jpeg":
leftImageLink = new LinkedResource(imageSource, "image/jpeg")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".gif":
leftImageLink = new LinkedResource(imageSource, "image/gif")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".png":
leftImageLink = new LinkedResource(imageSource, "image/png")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
}
htmlView.LinkedResources.Add(leftImageLink);
}
}
}
}
}
while (fbody.Contains("src='cid:"));
msg.AlternateViews.Add(htmlView);
}
if (templateID > 0)
{
//do smething else
}
if (file_names.Count > 0)
{
using (DataClassesDataContext db = new DataClassesDataContext())
{
for (int i = 0; i < file_names.Count; i++)
{
Attachment mailAttachment = new Attachment(Path.Combine(HttpRuntime.AppDomainAppPath, "EmailFiles/" + file_names[i].ToString()));
msg.Attachments.Add(mailAttachment);
}
}
}
if (IsUnsubscriptionLink.Equals(1))
{
string pathToApp = ConfigurationManager.AppSettings["EASYMAIL_PathToApplication"];
string unsubscribeText = "<br/>\r\n\r\n---------------------------\r\n<br/>" +
"To unsubscribe, please click this link:\r\n" +
pathToApp + "Unsubscribe.aspx";
msg.Body = plainText + unsubscribeText;
}
else
{
msg.Body = plainText + string.Empty;
}
client.Send(msg);
}
here is my gmail output for getting mail to my account :
how ever this my original mail generated from gmail is :
how ever i can't see full email rich text. guys please help me what's going wrong here...


few things about creating mail templates.
Attached sample HTML code to show what i mean.
example
in HTML just define image source as