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

  • Home
  • SEARCH
  • 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 7960795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:51:29+00:00 2026-06-04T04:51:29+00:00

I have an application that occasionally sends out an e-mail with three attachments. One

  • 0

I have an application that occasionally sends out an e-mail with three attachments.

One attachment is the file initially sent to my mailbox by a user, so I’m replying with the same file they sent me. I do this by MemoryStream, and it works just fine.

The other two files are a .PDF and an .XLSX file.

    var excelTemplatePath = GetFilePathToDefaultExcelFile();

    if (excelTemplatePath != null)
        mailMessage.Attachments.Add(new System.Net.Mail.Attachment(excelTemplatePath));

    var pdfPath = GetFilePathToPDFInstructions();

    if (pdfPath != null)
        mailMessage.Attachments.Add(new System.Net.Mail.Attachment(pdfPath));

Here’s the weird part. They attach just fine when I debug the application within Visual Studio. Perfect every time.

When I run the compiled .exe, whether from /BIN/ or wherever I choose to deploy it, it mangles the e-mail. It attaches no files, and simply sends something that looks like it serialized the file(s) into the e-mail text body:

cHMvYXBwLnhtbFBLAQItABQABgAIAAAAIQAkRr56YQEAAG0DAAAYAAAAAAAAAAAA
AAAAAKblAABjdXN0b21YbWwvaXRlbVByb3BzMy54bWxQSwECLQAUAAYACAAAACEA
te/KYaMAAADVAAAAEwAAAAAAAAAAAAAAAABl5wAAY3VzdG9tWG1sL2l0ZW0xLnht
bFBLAQItABQABgAIAAAAIQB/jqJ4TAEAAOYCAAAYAAAAAAAAAAAAAAAAAGHoAABj
dXN0b21YbWwvaXRlbVByb3BzMS54bWxQSwECLQAUAAYACAAAACEAvYRiI5AAAADb
AAAAEwAAAAAAAAAAAAAAAAAL6gAAY3VzdG9tWG1sL2l0ZW0yLnhtbFBLAQItABQA
BgAIAAAAIQCQ9oX78gAAAE8BAAAYAAAAAAAAAAAAAAAAAPTqAABjdXN0b21YbWwv
aXRlbVByb3BzMi54bWxQSwECLQAUAAYACAAAACEAZaNvWToEAACtDQAAEwAAAAAA
AAAAAAAAAABE7AAAY3VzdG9tWG1sL2l0ZW0zLnhtbFBLAQItABQABgAIAAAAIQDc
SoJLbAEAAJ4CAAARAAAAAAAAAAAAAAAAANfwAABkb2NQcm9wcy9jb3JlLnhtbFBL
BQYAAAAAGwAbADoHAAB68wAAAAA=


----boundary_0_61985b34-0fc6-4f91-99b8-464d8f613491

Content-Type: application/octet-stream; name="Microsoft Office 2003 Compatibility
 Installation Instructions.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

----boundary_0_61985b34-0fc6-4f91-99b8-464d8f613491--

(That goobeldy goop is just a small portion of all the junk contained in the e-mail, but it looks the same throughout.)

I’ve tried using a different constructor when creating the attachment, to include a MIME-TYPE of “application/pdf” and what not. When I did, it changed the Content-Type in the e-mail body to application/pdf, but the e-mail still contained all the garbage and did not attach the file.

Why would it work within the IDE and not from the .EXE? This is odd behavior to me. Thanks.

SOLUTION

The specific solution was setting the TransferEncoding to QuotedPrintable using System.Net.Mime.

 var attachment = new System.Net.Mail.Attachment(filePath);
 attachment.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
 mailMessage.Attachments.Add(attachment);

I now do this for each attachment and the files attach as desired.

  • 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-04T04:51:30+00:00Added an answer on June 4, 2026 at 4:51 am

    The specific solution to my problem was setting the TransferEncoding to QuotedPrintable using System.Net.Mime.

    var attachment = new System.Net.Mail.Attachment(filePath);  
    attachment.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
    mailMessage.Attachments.Add(attachment); 
    

    I now do this for each attachment and the files attach as desired.

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

Sidebar

Related Questions

I have a mail-in database application and I am finding that occasionally an email
I have a rails application that occasionally needs to do very slow network calls
We have an AIR application running on an Apple iPad, that occasionally experiences sudden
I have a PhoneGap application that works fine but occasionally is known to have
i have a .net winforms application that i want to be soundless. occasionally when
I have a C# .Net 3.5 application that sends a multicast Hello packet to
I have an application that logs information to a daily text file every second
I have a Windows application written in C++ that occasionally evaporates. I use the
I have a Silverlight 4 application (plug... http://audioorchard.com ...end plug) that is occasionally throwing
I have a small utility application that handles sockets, both TCP and UDP. Occasionally,

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.