我试图在HTML邮件中添加图像。当我保存它显示的是体为HTML文件,但是当我发送HTML体作为发电子邮件,通过的GMail,图像不显示。谁能告诉我原因?为什么图像不显示在Gmail邮件中的HTML邮件?
我设置图像的这样来源:
var image = body.GetElementsByTagName("img");
string imageAttachmentPath = Path.Combine(Globals.NotificationTemplatesPath, "Header.png");
foreach (XmlElement img in image)
{
img.SetAttribute("src", imageAttachmentPath);
break;
}
//thats the method in which i am sending email.
public static void SendMessageViaEmailService(string from,
string sendTo,
string carbonCopy,
string blindCarbonCopy,
string subject,
string body,
bool isBodyHtml,
string imageAttachmentPath,
Hashtable images,
List<string> attachment,
string title = null,
string embeddedImages = null)
{
Attachment image = new Attachment(imageAttachmentPath);
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true; // email body will allow html elements
msg.From = new MailAddress(from, "Admin"); // setting the Sender Email ID
msg.To.Add(sendTo); // adding the Recipient Email ID
if (!string.IsNullOrEmpty(carbonCopy)) // add CC email ids if supplied.
msg.CC.Add(carbonCopy);
msg.Subject = subject; //setting email subject and body
msg.Body = body;
msg.Attachments.Add(image);
//create a Smtp Mail which will automatically get the smtp server details
//from web.config mailSettings section
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "smtp.gmail.com";
SmtpMail.Port = 587;
SmtpMail.EnableSsl = true;
SmtpMail.UseDefaultCredentials = false;
SmtpMail.Credentials = new System.Net.NetworkCredential(from, "password");
// sending the message.
try
{
SmtpMail.Send(msg);
}
catch (Exception ex) { }
}
欢迎来到Stack Overflow。如果我们也看到你的工作会更好。你有没有尝试设置你的['IsBodyHtml'属性](http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx)?请阅读[常见问题],[问]和[帮助]作为开始.. – 2014-10-22 07:16:40
请发表您的代码 – 2014-10-22 07:20:53
@VinodVT我已发布代码 – Fahad 2014-10-22 07:29:57