【问题标题】:how to send an image via email without saving it to a folder before如何通过电子邮件发送图像而不将其保存到文件夹中
【发布时间】:2016-04-23 02:30:16
【问题描述】:

我正在使用 fileupload 将图像上传到 asp.net 网站,我需要通过电子邮件发送上传的图像来执行此操作我将图像保存到 erver 上的文件夹,然后我正在发送图像但我可以发送它之前没有保存到文件夹中,或者如果我需要将其保存到文件夹中,我可以在发送后立即删除它吗? 谢谢。

我的代码:

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);

【问题讨论】:

    标签: asp.net file-upload


    【解决方案1】:
    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);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2014-07-20
      • 1970-01-01
      • 2018-09-20
      • 2013-02-08
      相关资源
      最近更新 更多