Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么图像不在gmail的html邮件中显示?_C#_Html_Email - Fatal编程技术网

C# 为什么图像不在gmail的html邮件中显示?

C# 为什么图像不在gmail的html邮件中显示?,c#,html,email,C#,Html,Email,我正在尝试在HTML邮件中添加图像。当我将该正文保存为html文件时,它会显示,但当我通过GMail将该html正文作为电子邮件发送时,图像不会显示。谁能告诉我原因吗 我这样设置图像的源: var image = body.GetElementsByTagName("img"); string imageAttachmentPath = Path.Combine(Globals.NotificationTemplatesPath, "Header.png"); foreach (XmlEleme

我正在尝试在HTML邮件中添加图像。当我将该正文保存为html文件时,它会显示,但当我通过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) { }
}
请尝试以下代码部分:


您的image SRC属性很可能不是一个绝对的、可公开访问的URI。任何文件系统或本地URI都不会在电子邮件中显示图像

具体而言,这些措施不起作用:

c://test.png
test.png
/folder/test.png
http://localhost/test.png
http://internaldomain/test.png
确保您的图像URL是

绝对的,即从协议开始,如http:// 包括图像的完整路径 该域是公共域
欢迎来到堆栈溢出。如果我们也看到你的作品会更好。你有没有试着把你的名字也定下来?请阅读,作为开始,请发布您的code@VinodVT我已经发布了code@SonerGönül是的,我把它变成了现实。我发布了我用来发送电子邮件的方法的代码。收到邮件时,您是否尝试检查邮件?你可以查看它的源代码。
c://test.png
test.png
/folder/test.png
http://localhost/test.png
http://internaldomain/test.png