473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Add a string as a mail attachment text file.

I have a string:

sring Result = "This is the string I want sent as a text file"

I have MailMessage:

MailMessage TestMail = new MailMessage();
TestMail.From = "la**********@tmp.com";
TestMail.To = "la**********@tmp.com";
TestMail.BodyFormat = MailFormat.Text;
TestMail.Subject = "Test email";
TestMail.Body = "This would be the body of the email"
I want to add Result as a textfile attachement to the email. How can I
go about doing this? I would prefer if I didn't have to actually save
to the disk.

TestMail.Attachments.Add(Result); //obviously this would be too
easy.
SmtpMail.Send(TestMail);

Any thoughts? Can I somehow cast this string into a MailAttachment as
if by magic?

Larry.
Jul 19 '05 #1
2 2359
I think you are going to have to do the thing you don't want to do, which is
persist the string to a file, and then attach the file. On the upside, once
the mail is sent, there is nothing stopping your app from deleting the file.
--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.
_____________________________
"Larry Viezel" <la****@nominex.com> wrote in message
news:a3**************************@posting.google.c om...
I have a string:

sring Result = "This is the string I want sent as a text file"

I have MailMessage:

MailMessage TestMail = new MailMessage();
TestMail.From = "la**********@tmp.com";
TestMail.To = "la**********@tmp.com";
TestMail.BodyFormat = MailFormat.Text;
TestMail.Subject = "Test email";
TestMail.Body = "This would be the body of the email"
I want to add Result as a textfile attachement to the email. How can I
go about doing this? I would prefer if I didn't have to actually save
to the disk.

TestMail.Attachments.Add(Result); //obviously this would be too
easy.
SmtpMail.Send(TestMail);

Any thoughts? Can I somehow cast this string into a MailAttachment as
if by magic?

Larry.

Jul 19 '05 #2
Yup, Pete's correct.

You will have to create a text file and attach it.

hth,
Dave
www.aspNetEmail.com

"Pete Wright" <pe**@codemonkey.demon.co.uk> wrote in message news:<be********************@news.demon.co.uk>...
I think you are going to have to do the thing you don't want to do, which is
persist the string to a file, and then attach the file. On the upside, once
the mail is sent, there is nothing stopping your app from deleting the file.
--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.
_____________________________
"Larry Viezel" <la****@nominex.com> wrote in message
news:a3**************************@posting.google.c om...
I have a string:

sring Result = "This is the string I want sent as a text file"

I have MailMessage:

MailMessage TestMail = new MailMessage();
TestMail.From = "la**********@tmp.com";
TestMail.To = "la**********@tmp.com";
TestMail.BodyFormat = MailFormat.Text;
TestMail.Subject = "Test email";
TestMail.Body = "This would be the body of the email"
I want to add Result as a textfile attachement to the email. How can I
go about doing this? I would prefer if I didn't have to actually save
to the disk.

TestMail.Attachments.Add(Result); //obviously this would be too
easy.
SmtpMail.Send(TestMail);

Any thoughts? Can I somehow cast this string into a MailAttachment as
if by magic?

Larry.

Jul 19 '05 #3

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

Similar topics

2
by: knoak | last post by:
Hi there, I've found a script at these great Google fora. a script to send emails with attachments. The script is below this message, name etc. aren't mine, but from the original post. My...
3
by: marsandys | last post by:
Hello, I have this code below, which I am trying to have it send HTML formatted mail with embedded images. I can get this to send the mail, but it spits out a bunch of junk . I know this should...
0
by: David | last post by:
I have a C# application that functions as follows: 1. Log onto a pop3 mail account 2. search for any messages from a given source. 3. Get the attachment from the message. (This attachment will...
6
by: Karl Groves | last post by:
I'm trying to work out a mail system which can send an attachment as well as an HTML formatted message (and a default plain text version). I found some pretty good code on PHP.net and modified it...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
6
by: cover | last post by:
I'm using PHP 5 at home w/Apache & MySQL on a test system where I write through a form to a database and also send an email to people on a drop down list. Purpose for this is an electronic log at...
2
by: eng.sharif | last post by:
hi group how i can send mail and attachement in php with "mail function " $s = mail($to,$subject,$cont, $headers); can anyone help
9
by: deepaks85 | last post by:
Dear Sir, I have created a simple request form which will be mailed to me. Now I want to attach files and send it through that request form. For this I am using the following script: ...
2
by: gezerpunta | last post by:
Hi I used pear api to make this mail but I can t add multipart.My mail structure is like that. part 1: a file part 2: multipart part 1: a file part 2: a file
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.