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 6859175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:15:02+00:00 2026-05-27T02:15:02+00:00

I have a function that accepts a string and generates an email attachment based

  • 0

I have a function that accepts a string and generates an email attachment based on that string. It works fine for html pages, text documents, and so forth but I can not get it to generate a PDF file.

Code:

Public Sub SendMail _
( _
ByVal strFrom As String _
, ByVal strTo As String _
 , ByVal strSubject As String, ByVal strBody As String _
 , Optional ByVal attachment As String = "" _
 , Optional ByVal filename As String = "Attachment.HTML" _
)

    Dim sendMail As New SmtpClient
    Dim mail As New MailMessage(strFrom, strTo)
    Dim userToken As New Object


        mail.Subject = strSubject
        mail.Body = strBody

        mail.IsBodyHtml = True


        Using MemoryStream = New MemoryStream

            If attachment.Length <> 0 Then
                        Dim data As Byte() = Encoding.ASCII.GetBytes(attachment)
                        MemoryStream.Write(data, 0, data.Length)
                        MemoryStream.Seek(0, SeekOrigin.Begin)
                        MemoryStream.Position = 0

                        Dim content As New ContentType()
                        content.MediaType = MediaTypeNames.Application.Octet
                        content.Name = filename

                        Dim newAttach As New Attachment(MemoryStream, content)
                        mail.Attachments.Add(newAttach)
            End If


            sendMail.DeliveryMethod = SmtpDeliveryMethod.Network
            sendMail.Host = "SERVER"
            sendMail.UseDefaultCredentials = False
            sendMail.Credentials = New System.Net.NetworkCredential("UN", "PW")

            sendMail.Send(mail)


        End Using

If I save the file attachment as Whatever.PDF i get the error that it was not encoded properly. Not sure what I need to do to have this work with PDF, have tried searching google but not finding anything that helps me.

EDITED:

I am using datadynamics active reports PDF exporter to generate the PDF

dim pdf as new datadynamics.activereports.export.pdf.pdfexport
sendmail("from@", "to@", "test", "test", pdf.tostring, "pdf.pdf")

I think the problem is I am converting the PDF to a string, and then trying to convert it back to a PDF and attach it to the email but I am not 100% sure.

Thanks.

  • 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-05-27T02:15:02+00:00Added an answer on May 27, 2026 at 2:15 am

    I’m not familiar with this reporting technology, but according to documentation you should use something like this:

    DataDynamics.ActiveReports.Export.Pdf.PdfExport p = new DataDynamics.ActiveReports.Export.Pdf.PdfExport();
    string tmp = Path.GetTempFileName();
    p.Export(rpt.Document, tmp, "1-10000");
    byte[] pdf = File.ReadAllBytes(tmp);
    File.Delete(tmp);
    

    and build MemoryStream from pdf array or add attachment from tmp file.

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

Sidebar

Related Questions

I have a sql function that accepts keywords and returns a full text search
I have a function that accepts a string, that is: void log_out(char *); In
I have a function that accepts an anonymous function as an argument and sets
I have a function that accepts a char* as one of its parameters. I
I have a function that accepts a class (not an instance) and, depending on
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function that accepts a generic parameter T that is of type
I have a function that accepts a variable number of parameters: foo (Class... types);
I have a javascript function that accepts a number and performs a mathematical operation
In .NET, the Generics Lists have a sort function that accepts IComparer or Comparison

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.