【问题标题】:How to send image as attachement without saving it in file system?如何将图像作为附件发送而不将其保存在文件系统中?
【发布时间】:2011-05-24 13:16:10
【问题描述】:

我有一个aspx页面,内容:

代码:

<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/JD.jpg" />

<img ID="Image2" runat="server" alt="" src="~/Images/JD.jpg" />

我必须将此图像作为邮件附件发送而不保存在文件系统中?

Actallay 我必须通过邮件发送错误报告...就像那个用户截屏并发送给管理员...

请给我建议..

【问题讨论】:

  • 但它已经保存在~/Images/JD.jpg?您是否尝试改用asp:FileUpload
  • 如果你指向那个路径,它已经在文件系统上,为什么不从那里拿走呢?

标签: asp.net


【解决方案1】:

仅供参考。
Sending Email with attachment in ASP.NET using SMTP Server

/* Beginning of Attachment1 process   & 
   Check the first open file dialog for a attachment */
if (inpAttachment1.PostedFile != null)
{
/* Get a reference to PostedFile object */
HttpPostedFile attFile = inpAttachment1.PostedFile;
 /* Get size of the file */
 int attachFileLength = attFile.ContentLength; 
 /* Make sure the size of the file is > 0  */
 if (attachFileLength > 0)
 {
 /* Get the file name */
 strFileName = Path.GetFileName(inpAttachment1.PostedFile.FileName);
 /* Save the file on the server */      
 inpAttachment1.PostedFile.SaveAs(Server.MapPath(strFileName));  
 /* Create the email attachment with the uploaded file */
 MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
 /* Attach the newly created email attachment */      
 mailMessage.Attachments.Add(attach);
 /* Store the attach filename so we can delete it later */
 attach1 = strFileName;
 }
}

【讨论】:

  • 嗨,Thomas,实际上我正在截取我的网页截图并将其作为图像发送到邮件中。此屏幕截图图像没有物理位置。请告诉我我会怎么做?谢谢
  • @Pankaj Pareek:截取网页截图后,您必须保存它,然后使用 FileUpload 控件将其与邮件消息一起附加。
  • @Thomas ,实际上我正在开发 flex 和 asp.net 应用程序。当我点击某个按钮时,pop 会出现之前的屏幕,详细信息。现在我必须通过邮件发送这张图片和详细信息。
  • @Pankaj Pareek:我对 Flex 了解不多。但是如果你不能点击,那么你可以使用键盘的键来保存它,然后使用键上传它。
猜你喜欢
  • 2011-02-07
  • 1970-01-01
  • 2015-04-15
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多