0

I want to send a pdf file via email, the file arrives but it damaged, any idea?

    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)
  • http://stackoverflow.com/questions/527214/how-do-i-add-an-attachment-to-an-email-using-system-net-mail discusses how to attach files to mail. Lots of other questions and answers here on SO regarding this. – Peter Lillevold Apr 24 '15 at 23:15
  • I don't know if I must to use header method, how I get the the file?, thanks – undertakerevil Apr 28 '15 at 16:09
  • is your issue with the server-side or the client-side of this? Your question is very unclear. To get better answers on SO, try to formulate a good question and clearly show what you have tried so far. Also, do some Google research first, there are massive amounts of samples out there, both on how to serve files (the server-side) from a webservice and also how to download such files (the client-side). – Peter Lillevold Apr 29 '15 at 07:15
  • sorry if my question is poorly made, I am consuming a web service within its documentation is a code to download a file, it is the same code that I put up, then my intention is to create a button to send the file by mail mail, I commented that if I worked with email in .NET, but I have no idea how to get the file (without downloading) and then attach it to email, thanks – undertakerevil Apr 29 '15 at 16:33

0 Answers0