【发布时间】:2014-12-17 14:10:19
【问题描述】:
我正在尝试在 HTML 邮件中添加图像。当我将该 body 保存为 html 文件,但当我通过 GMail 将该 html 正文 作为电子邮件发送时,它会显示strong>,图像不显示。谁能告诉我原因?
我是这样设置图片来源的:
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。如果我们也看到你的作品会更好。您是否也尝试设置您的
IsBodyHtmlproperty?请阅读FAQ、How to Ask 和help center 作为开始.. -
请发布您的代码
-
@VinodVT 我已经发布了代码
-
@SonerGönül 是的,我已将其设置为真的。我发布了我用来发送电子邮件的方法的代码。
-
您是否在收到邮件时尝试检查邮件?你可以查看它的源代码。