【问题标题】:ASPNet EMail attachment from SQL BLOB来自 SQL BLOB 的 ASPNet 电子邮件附件
【发布时间】:2010-11-13 08:45:51
【问题描述】:

我们将预定的电子邮件信息存储在 SQL Server 2005 中。电子邮件信息中包含 0 - 3 个不同文件类型的附件。我有一个运行“x”分钟的 VB.net Windows 服务,使用来自 SQL Server 的电子邮件信息填充数据集,构建电子邮件,并通过 ASPNet EMail 发送它们。

尝试从 BLOB 构建和添加附件会导致电子邮件发送方法超时,即使附件只是一个 15 字节的文本文件。将路径直接硬编码到文件可以正常工作。试了好几种方法都不行。

【问题讨论】:

    标签: asp.net sql-server email blob


    【解决方案1】:

    嗯,我做过类似的事情。对于我的每个附件,我将数据存储为二进制列,以及包含文件大小(以字节为单位)的单独列。为了从数据库中获取,我写了类似的东西(使用SqlCommand 和 SqlDataReader 类):

    attachment = new byte[size];
    
    sqlReader.GetBytes(sqlReader.GetOrdinal("attachment"), 0, attachment, 0, size);
    
    System.IO.MemoryStream s = new System.IO.MemoryStream(attachment, true);
    s.Write(attachment, 0, attachment.Length);
    

    而且太依附于一个MailMessage类(简称mm);

    System.IO.MemoryStream s = new System.IO.MemoryStream(attachment, false);
    
    Attachment attached = new Attachment(s, "some file name");
    mm.Attachments.Add(attached);
    

    也许这些摘录会有所帮助!我从两个不同的自定义类中提取了代码,因此每个提取物中的 MemoryStream 对象有点笨拙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2014-10-24
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 2019-02-13
      相关资源
      最近更新 更多