将内存流附加到电子邮件时参数过多



我有一个数据库字段varbinary,用于存储文档和pdf。

我想附加这样的流并通过电子邮件发送。电子邮件在没有附件的情况下工作正常。我尝试使用文件进行测试(而不是从数据库中检索数据),但是我被困在"太多参数到'公共子新()'

请帮忙。

Dim fileName As String = "C:UserstzveiDocumentstest.pdf"
        ' Get the file stream . 
        ' Requires the System.IO namespace.
        Dim fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
        Dim ms As New MemoryStream()
        ms.SetLength(fs.Length)
        fs.Read(ms.GetBuffer(), 0, CInt(fs.Length))
        m.Attachments.Add(New Attachment(ms, "test.pdf", "application/pdf")) 'here is the error Too many arguments
        ms.Flush()
        fs.Close()
        ms.Close()`      

谢谢斯图尔特LC这奏效了

   Dim fileName As String = "C:UserstzveiDocumentsReferenceLetter.pdf"
    ' Get the file stream for the error log. 
    ' Requires the System.IO namespace.
    Dim fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
    Dim mstream As New MemoryStream()
    mstream.SetLength(fs.Length)
    fs.Read(mstream.GetBuffer(), 0, CInt(fs.Length))
    Dim attach1 As New System.Net.Mail.Attachment(mstream, "blah", "application/pdf")
    m.Attachments.Add(attach1)

最新更新