user2849412
user2849412

Reputation: 13

how to send an image via email without saving it to a folder before

I am uploading images to an asp.net website using fileupload and i need to send the uploaded images via email to do this i am saving the image to a folder on the erver and then i am sending the image but can i send it without saving it to a folder before or if i need to save it to a folder can i delete it as soon as it's sent? thanks.

my code:

string filename = Path.GetFileName(file.FileName);
                file.SaveAs(Server.MapPath("UploadImages/" + filename));
                string attachmentPath = Server.MapPath("UploadImages/" + filename);
                Attachment inline = new Attachment(attachmentPath);
                inline.ContentDisposition.Inline = true;
                inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
                inline.ContentType.Name = Path.GetFileName(attachmentPath);
                mail.Attachments.Add(inline);

Upvotes: 1

Views: 73

Answers (1)

Kyle
Kyle

Reputation: 5547

using System.Net.Mail;

[WebMethod]
public void SendFile(HttpPostedFileBase file)
{
    //...setup mail message etc
    Attachment attachment = new Attachment(file.InputStream, file.FileName);
    message.Attachments.Add(attachment);
}

Upvotes: 1

Related Questions