Pankaj Pareek
Pankaj Pareek

Reputation: 589

How to send image as attachement without saving it in file system?

I have one aspx page which content :

Code:

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

OR

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

I have to send this image as attachement in mail without saving in file system?

Actallay i have to send bug report in mail...It's like that user taking screen shot and send to admin...

Please suggest me..

Upvotes: 1

Views: 1408

Answers (1)

Amit
Amit

Reputation: 22076

This is for reference only.
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;
 }
}

Upvotes: 4

Related Questions