Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > using system.net.mail attachment is empty

Reply
Thread Tools

using system.net.mail attachment is empty

 
 
=?Utf-8?B?dGhlV2l6YXJkMQ==?=
Guest
Posts: n/a
 
      04-18-2006
The following sends my email, but the attachment is empty. The attachment
should contain the data that is in the string that was created from the
xmlReader.

I have a stored procedure written using For XML explicit, and it returns an
xml reader. Then the following:

xmlRdr.MoveToContent();
string myTemp = xmlRdr.ReadOuterXml();

System.IO.MemoryStream memStream = new System.IO.MemoryStream();
StreamWriter sw = new StreamWriter(memStream);
sw.Write(myTemp);

System.Net.Mail.MailMessage mail = new System.Mail.MailMessage();
mail.From = new System.Net.Mail.MailAddress("i put my email address here");
mail.To.Add("I put my email address here, because it is just a test");
mail.Subject = "This is a test";
mail.Body = "this content is in the body";

System.Net.Mail.Attachment emailAttachment = new
System.Net.Mail.Attachment(memStream, "text/xml");
System.Net.Mime.ContentDisposition contentDispo =
emailAttachment.ContentDisposition;

contentDispo.FileName = "myFirstText.xml";
mail.Attachments.Add(emailAttachment);

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.put
myemailservernamehere");
smtp.Send(mail);
memStream.Close();

The above sends the email with an attachment, but the attachment is empty.

Note the xmlReader produces xml with a unique root, so no problem with the
string. I can see the data in the string when I debug, but the attachment
does not have it.
 
Reply With Quote
 
 
 
 
pradeep via DotNetMonster.com
Guest
Posts: n/a
 
      04-18-2006
hi,

Try using the following piece of code for filling the memory stream

MemoryStream memStream = new MemoryStream();
UnicodeEncoding encoding = new UnicodeEncoding();
Byte[] byteArray = encoding.GetBytes(myTemp);
memStream.Write(byteArray, 0, byteArray.GetLength(0));
memStream.Seek(0, SeekOrigin.Begin);


regards,
pradeep

theWizard1 wrote:
>The following sends my email, but the attachment is empty. The attachment
>should contain the data that is in the string that was created from the
>xmlReader.
>
>I have a stored procedure written using For XML explicit, and it returns an
>xml reader. Then the following:
>
>xmlRdr.MoveToContent();
>string myTemp = xmlRdr.ReadOuterXml();
>
>System.IO.MemoryStream memStream = new System.IO.MemoryStream();
>StreamWriter sw = new StreamWriter(memStream);
>sw.Write(myTemp);
>
>System.Net.Mail.MailMessage mail = new System.Mail.MailMessage();
>mail.From = new System.Net.Mail.MailAddress("i put my email address here");
>mail.To.Add("I put my email address here, because it is just a test");
>mail.Subject = "This is a test";
>mail.Body = "this content is in the body";
>
>System.Net.Mail.Attachment emailAttachment = new
>System.Net.Mail.Attachment(memStream, "text/xml");
>System.Net.Mime.ContentDisposition contentDispo =
>emailAttachment.ContentDisposition;
>
>contentDispo.FileName = "myFirstText.xml";
>mail.Attachments.Add(emailAttachment);
>
>System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.put
>myemailservernamehere");
>smtp.Send(mail);
>memStream.Close();
>
>The above sends the email with an attachment, but the attachment is empty.
>
>Note the xmlReader produces xml with a unique root, so no problem with the
>string. I can see the data in the string when I debug, but the attachment
>does not have it.


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200604/1
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting "empty" attachment with smtplib Tobiah Python 4 11-15-2012 05:26 PM
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
empty lists vs empty generators Brian Roberts Python 12 05-04-2005 08:59 PM
Check if a directory is empty and empty it Marcia Hon C Programming 8 02-14-2004 03:53 AM
empty/non-empty element John XML 1 07-16-2003 10:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57