为什么我的图片没有显示在电子邮件中?

时间:2015-08-19 20:42:26

标签: c# asp.net email

我有一个ecard应用程序,允许用户选择图像并发送电子邮件。但我无法弄清楚如何发送电子邮件是我的代码。

protected void SendEmail()
{
    StringBuilder message;
    Attachment attachFile;
    string sImage = System.Web.HttpContext.Current.Server.MapPath("~/DesktopModules/KDMC_EcardList/images/" + txtCapture.Text);
    LinkedResource yourPictureRes = new LinkedResource(txtCapture.Text, MediaTypeNames.Image.Jpeg);
    yourPictureRes.ContentId = "YourPictureId";
    altView.LinkedResources.Add(yourPictureRes);
    //Internal Message
    message = new StringBuilder();
    message.AppendLine(@"<p><img src=cid: sImage /></p>");
    message.AppendLine(@"<pre><table style='width:650px; word-break:break-word; height:auto;'>
                             </td><tr><td style='width:150px;'>From: </td><td style='width:500px;'>" + txtFName.Text + " " + txtLName.Text + @"
                            </td><tr><td>To: </td><td>" + txtFriendFName.Text + " " + txtFriendLName.Text + @"
                            </td><tr><td>Room Number: </td><td>" + txtRoom.Text + @"
                           </td><tr><td>Message: </td><td>" + txtMessage.Text + @"                                 
                           </td><tr><td>Date Sent: </td><td>" + DateTime.Now.ToString() + "</td></tr></table></pre>");

    //attachFile = new Attachment(FileUploadVideo.PostedFile.InputStream, strFileName);
    System.Threading.Thread.Sleep(1000);
    // need to create new reference to attachment, cannot use same reference to send email twice
    //attachment = new Attachment(theMemoryStream, strSubject);
    Mail.SendMail("test@test.net", "test@test.net", "", "test@test.net",
            "test@test.net", MailPriority.Normal, "A new Ecard has been submitted", MailFormat.Html, Encoding.UTF8, message.ToString(),
            new List<Attachment>() { }, null, null, null, null, Host.EnableSMTPSSL);  
}

我尝试按照此处的示例C# add image to email body以及社区中的其他解决方案,但我仍然无法找到解决方案。

2 个答案:

答案 0 :(得分:1)

您需要添加embedded image to the email,然后才能在模板中使用M <- 200; # number of rows N <- 200; # number of colums g <- 10 I <- matrix(sample(0:1, M*N, repl=T, prob= c(1-g/N,g/N)), M, N); ID:

cid

答案 1 :(得分:0)

您正在将IMG标记的src的CID设置为var text = "Hello Victor Sigler" if let indexOf = text.rangeOfString("Victor")?.startIndex { println(indexOf) //6 } 的结果。这将是您机器上的完整路径。我认为如果您提到附件需要进行的是文件名(Server.MapPath(...)