Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:45:20+00:00 2026-06-04T19:45:20+00:00

i am trying to send PDF file using itextsharp , the email sends fine

  • 0

i am trying to send PDF file using itextsharp , the email sends fine but with out the pdf attachment
can some tell me what is wrong with my code ?
here is my code :

Dim pdfFile As MemoryStream = New MemoryStream()
            Dim d As Document = New Document(PageSize.A4, 60, 60, 40, 40)
            Dim w As PdfWriter = PdfWriter.GetInstance(d, pdfFile)
            w.Open()
            w.Add(New Paragraph("do foo something "))

            Dim message As New MailMessage()
            message.From = New MailAddress("******")
            message.To.Add(New MailAddress("***************"))
            message.Subject = "new image "
            message.Body = "this is the apak chart img"
            Dim data As New Attachment(pdfFile, New System.Net.Mime.ContentType("application/pdf"))
            message.Attachments.Add(data)
            Dim client As New SmtpClient()
            client.Host = "smtp.gmail.com"
            client.Credentials = New NetworkCredential("*****", "*******")
            client.EnableSsl = True
            client.Port = 587
            client.Send(message)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:45:22+00:00Added an answer on June 4, 2026 at 7:45 pm

    Try flushing the writer and rewinding the stream:

    Dim pdfFile As MemoryStream = New MemoryStream()
    Dim d As Document = New Document(PageSize.A4, 60, 60, 40, 40)
    Dim w As PdfWriter = PdfWriter.GetInstance(d, pdfFile)
    w.Open()
    w.Add(New Paragraph("do foo something "))
    
    w.CloseStream = false;
    d.Close();
    pdfFile.Position = 0;
    

    Adapted from: iTextSharp – Sending in-memory pdf in an email attachment

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send an email that contains an attachment (a pdf file)
I'm trying to send a byte[] (using PUT) with Restlet but I can't find
I have been struggling with trying to send an email with an attachment using
Trying to send a PHP email the easy way but I cannot work out
Django email attatch issues. I am trying to attach a PDF file and send
I'm trying to send a PDF attachment through JavaMail, but when I receive the
I'm trying out http requests to download a pdf file from google docs using
I'm trying to send a PDF file for a Kindle device. If I send
Trying to send some email in my C# app. I am behind a proxy
I am trying to send email using Exchange 2007 from a console app using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.