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) { }
}
스택 오버플로에 오신 것을 환영합니다. 우리가 당신의 일을 또한 보는 것이 좋을 것입니다. ['IsBodyHtml' 속성을 설정하려고 시도 했습니까 (http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx)? –
코드를 게시하십시오. –
@VinodVT 코드 – Fahad