MIME attachment and memory stream



Hi,
I want to send a memorystream as an attachment. Avoiding using a
filestream as this code will be part of a Webservice and I figured it
was easier to keep the data in memory rather than writing it to disc
on the webserver.
But if this is not the way to do it then please let me know.

My code 'works' but the attachment is empty when read by the mail
client. The attachment also behaves strangely in that it won't open
from inside the mail client, you have to 'save as' then open the saved
file (which is empty, 0kB)
Would appreciate pointer in the right direction.
code follows.
Thanks
Bob

private bool GenerateEmail(List<Job> list)
{
SmtpClient c = new SmtpClient("mailserver");
ContentType ct = new ContentType("text/plain;
charset=us-ascii");
Stream stream = new MemoryStream();
Attachment a = new
Attachment(GeneratePendingStream(stream,list),ct);

MailMessage m = new
MailMessage("somebodyt@somewhere","mailaddress@mailserver") {Body =
"Test Message"};
m.Attachments.Add(a);
c.Send(m);
stream.Close();
return true;

}
/// <summary>
/// Generate stream of pending jobs
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
private Stream GeneratePendingStream( Stream stream,List<Job>
list)
{


StreamWriter wr = new StreamWriter(stream);
foreach (Job job in list)
{
string sLine = job.CustomerId.ToString() + "," +
job.CustomerName;
wr.WriteLine(sLine);
}
wr.Flush();

return stream;
}
.



Relevant Pages

  • Re: .NET CF - Webservice - deserialize soap xmp stream
    ... Ziel war es nicht einen gezippten Stream abzuspeichern sondern manuell den ... letzten abgespeicherten webservice xml stream (der, ... Der proxy des Webservice deserialisiert ja automatisch ... "Frank Dzaebel" wrote: ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: WebService Problem
    ... > I am creating webservice DocManager to store documents.I have a method ... > where path is path of file on server and stream is stream of document. ... compile the client it gives compile time error ... > public void Uploadfile ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Help need calling a webservice.
    ... i'm calling a webservice generated with oracle webservice java tools. ... private int priority; ... private Stream chainedOutputStream; ... private String filename; ...
    (microsoft.public.dotnet.framework.webservices)
  • Complex webservice scenario.
    ... i'm calling a webservice generated with oracle webservice java tools. ... private int priority; ... private Stream chainedOutputStream; ... private String filename; ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • WebService Problem
    ... where path is path of file on server and stream is stream of document. ... I feel the webservice exposes a stream object which is contradicting with it.I chnaged the function to ... public void Uploadfile(string path,System.IO.Stream instream) ...
    (microsoft.public.dotnet.framework.aspnet.webservices)