当我通过电子邮件发送时,pdf损坏了

时间:2015-04-24 23:10:58

标签: asp.net vb.net

我想通过电子邮件发送一个pdf文件,文件到了但是它已经损坏了,不知道吗?

    Dim buffer As Byte() = New Byte(6499) {}
    Dim bytesRead As Integer = 0         
    bytesRead = file.FileByteStream.Read(buffer, 0, buffer.Length)
    Dim ms As New MemoryStream(bytesRead)
    ms.Seek(0, SeekOrigin.Begin)
    mail.Attachments.Add(New Attachment(ms, "test.pdf", "application/pdf"))
    mail.IsBodyHtml = False
    mail.From = New System.Net.Mail.MailAddress("xxxxx@gmail.com")
    mail.To.Add("yyyyyy@gmail.com")
    mail.Subject = "test subject"
    mail.Body = "test body"
    mail.Priority = System.Net.Mail.MailPriority.Normal
    Dim smtp As New System.Net.Mail.SmtpClient
    smtp.Host = "smtp.gmail.com"
    smtp.Credentials = New System.Net.NetworkCredential("mymail@gmail.com", "pass")
    smtp.Port = 587
    smtp.EnableSsl = True
    smtp.Send(mail)

0 个答案:

没有答案