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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:15:30+00:00 2026-05-11T07:15:30+00:00

See also this question: Can I pass a System.Net.MailMessage to a WCF service? I’d

  • 0

See also this question: Can I pass a System.Net.MailMessage to a WCF service?

I’d like to add attachments to the mail being sent. Attachments are either files on the local disc, or dynamically created Streams. A WCF contract can contain a Stream, but only when all arguments are of type Stream. So, what is the best way to pass one or more Attachments to a WCF service?

  • 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. 2026-05-11T07:15:30+00:00Added an answer on May 11, 2026 at 7:15 am

    Alright I’ve solved this myself. The trick here is to convert the attachment to a Base64 encodes string, much the same way email systems do this. I’ve created a class to handle this. Posted here for others:

     [DataContract]     public class EncodedAttachment     {         [DataMember(IsRequired=true)]         public string Base64Attachment;          [DataMember(IsRequired = true)]         public string Name;          /// <summary>         /// One of the System.Net.Mime.MediaTypeNames         /// </summary>         [DataMember(IsRequired = true)]         public string MediaType;     }   public EncodedAttachment CreateAttachment(string fileName)         {             EncodedAttachment att = new EncodedAttachment();             if (!File.Exists(fileName))                 throw new FileNotFoundException('Cannot create attachment because the file was not found', fileName);              FileInfo fi = new FileInfo(fileName);             att.Name = fi.Name;             att.MediaType = System.Net.Mime.MediaTypeNames.Text.Plain;              using (FileStream reader = new FileStream(fileName, FileMode.Open))             {                 byte[] buffer = new byte[reader.Length];                 reader.Read(buffer, 0, (int)reader.Length);                 att.Base64Attachment = Convert.ToBase64String(buffer);             }             return att;         } 

    And on the client side:

    public void SendEmail(SmallMessage msg)         {             using (MailMessage message = new MailMessage())             {                 message.Body = msg.Body;                 message.Subject = msg.Subject;                 message.To.Add(new MailAddress(msg.To));                 message.From = new MailAddress(msg.From);                 foreach (EncodedAttachment att in msg.Attachments)                 {                     message.Attachments.Add(CreateAttachment(att));                 }                  SmtpClient client = new SmtpClient();                 client.Send(message);             }         }   Attachment CreateAttachment(EncodedAttachment encodedAtt) {     MemoryStream reader = new MemoryStream(Convert.FromBase64String(encodedAtt.Base64Attachment));     Attachment att = new Attachment(reader, encodedAtt.Name, encodedAtt.MediaType);     return att;             } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See also SO 1664677 I get this error 2: Syntax error: ( unexpected when
I know you can print with printf() and puts() . I can also see
Consider this class: class foo(object): pass The default string representation looks something like this:
see also Differences between LINQ to Objects and LINQ to SQL queries We are
See also: Emacs behind HTTP proxy Is it possible to tell emacs to automatically
What are "iterable", "iterator", and "iteration" in Python? How are they defined? See also:
I have 3 main elements in my XML layout (also see the image): The
see this demo from jquery ui you have to hold down the Ctrl key
See title. Additionally, how can I tell if a given child element is only
My guesses were wrong, and had nothing to do with the answer. This question

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.