473,748 Members | 11,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using system.net.mail attachment is empty

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.MoveToCo ntent();
string myTemp = xmlRdr.ReadOute rXml();

System.IO.Memor yStream memStream = new System.IO.Memor yStream();
StreamWriter sw = new StreamWriter(me mStream);
sw.Write(myTemp );

System.Net.Mail .MailMessage mail = new System.Mail.Mai lMessage();
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(mem Stream, "text/xml");
System.Net.Mime .ContentDisposi tion contentDispo =
emailAttachment .ContentDisposi tion;

contentDispo.Fi leName = "myFirstText.xm l";
mail.Attachment s.Add(emailAtta chment);

System.Net.Mail .SmtpClient smtp = new System.Net.Mail .SmtpClient("sm tp.put
myemailserverna mehere");
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.
Apr 18 '06 #1
1 5907
hi,

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

MemoryStream memStream = new MemoryStream();
UnicodeEncoding encoding = new UnicodeEncoding ();
Byte[] byteArray = encoding.GetByt es(myTemp);
memStream.Write (byteArray, 0, byteArray.GetLe ngth(0));
memStream.Seek( 0, SeekOrigin.Begi n);
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.MoveToC ontent();
string myTemp = xmlRdr.ReadOute rXml();

System.IO.Memo ryStream memStream = new System.IO.Memor yStream();
StreamWriter sw = new StreamWriter(me mStream);
sw.Write(myTem p);

System.Net.Mai l.MailMessage mail = new System.Mail.Mai lMessage();
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.Mai l.Attachment emailAttachment = new
System.Net.Mai l.Attachment(me mStream, "text/xml");
System.Net.Mim e.ContentDispos ition contentDispo =
emailAttachmen t.ContentDispos ition;

contentDispo.F ileName = "myFirstText.xm l";
mail.Attachmen ts.Add(emailAtt achment);

System.Net.Mai l.SmtpClient smtp = new System.Net.Mail .SmtpClient("sm tp.put
myemailservern amehere");
smtp.Send(mail );
memStream.Clos e();

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.c om
http://www.dotnetmonster.com/Uwe/For...p-net/200604/1
Apr 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3273
by: PeterR | last post by:
I've spent weeks trying to write a function that is simple to use for sending emails with attachments, but I my programming skills are not that advanced. I've noticed a few postings in these newsgroups with the same problem, so I just want to share my solution. I recommend using libmail from http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en it has made my university project much simplier now! :-)
2
8697
by: New User | last post by:
Hi, I have a PDF file that I am trying to send as an attachment through a C# program. Even though the PDF file can be opened by itself, sometimes the same file cannot be opened as an attachment. If I try and open the original PDF file I have no problems. I have used System.Web.Mail.MailMessage to create an email and an SMTPMail object to send the mail.
0
5719
by: Balakrsihna | last post by:
Hi All, Can anyone tell me how to replace an image in MS Word 2003 using c#.net. I am converting an html file to word doc and sending this as attachment using System.Web.Mail; the recipient could not see the image in attachment. I am using Inlinepicture.Addpicture but still not working
8
1922
by: Ajit | last post by:
Is there anyway to move attachments from a incoming email into a specified folder using System.Web.Mail ? has anyone done this ? Any help is appreciated.
2
4532
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic from using system.web.mail to system.net.mail (of course vs is telling me system.web.mail is obsolete). In .Net 1.1, the files deleted with no problem but in .Net 2 when I attempt to delete I receive The process cannot access the file ...'...
4
2364
by: Max | last post by:
hi I am using System.Web.Mail.MailMessage with System.Web.Mail.SmtpMail to send mail. now the my question is, Is it compulsory to add fields smtpauthenticate, sendusername and sendpassword fields to MailMessage Object????. mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
2
2673
by: Ruud | last post by:
Just before leaving for a holiday my collegue modified this script. Now it won't send any body text (The data filled in on the form) and in an error condition it won't send any attachments either. Because I don't understand PHP I cannot find the error. Who is willing to help? regards Ruud
11
3510
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the programs capabilities. Searching this forum I did not find any related information so if I have chosen poorly, I would appreciate a suggestion of a more appropriate dotnet forum. Now what I wish is the ability to send bcc's rather than to: (would be...
1
1891
by: rengaraj | last post by:
hi dears! in my webapp i have some users, thats are in 3 Roles. i want to do communication between them via mail system. this means that Role 1 attach one file and this file must send via mail system to Role 2 (Role 2 mut can see in his page, attachment file and username that send this attachment file) and also Role 2 after doing some works, send this attachment or new attachment file to users in Role 3 and ....(My server is tomcat) i...
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.