【发布时间】:2015-11-13 07:56:57
【问题描述】:
我有一个电子贺卡应用程序,允许用户选择图像并发送电子邮件。但我无法弄清楚如何发送电子邮件,这是我的代码。
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 此处的示例以及社区中的其他解决方案进行操作,但我仍然无法找到解决方案。
【问题讨论】:
-
发布链接的帖子似乎更符合您的需求stackoverflow.com/questions/1113345/…