473,383 Members | 1,870 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,383 software developers and data experts.

Mail message

To create a Mail Message, i can use the MailMessage(from, to) and so
send the mail. But how should i change the code in case there is also
a file to attach in the form? (let's say that i have already placed
the upload-file control on the page).

Thanks
~V

Oct 8 '07 #1
6 1431
Vinnie,

You could just create instances of the Attachment class, passing in the
InputStream property from the HttpPostedFile instance that corresponds to
the uploaded file (which you get from the collection exposed by the Files
property on the HttpRequest instance).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vinnie" <ce**********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
To create a Mail Message, i can use the MailMessage(from, to) and so
send the mail. But how should i change the code in case there is also
a file to attach in the form? (let's say that i have already placed
the upload-file control on the page).

Thanks
~V
Oct 8 '07 #2
On Oct 8, 2:06 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Vinnie,

You could just create instances of the Attachment class, passing in the
InputStream property from the HttpPostedFile instance that corresponds to
the uploaded file (which you get from the collection exposed by the Files
property on the HttpRequest instance).

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Hi Nicholais, thanks for your help.

since it's my first time in writing a mail massege code, do you think
you can post a sample code that i can study and so apply to the form
i'm working on?

This is what's on the page:

To, From, Subject, Body of a mail message;
Upload-file field;
Submit button.

Thanks
Oct 8 '07 #3
On Oct 8, 2:25 pm, vinnie <centro.ga...@gmail.comwrote:
On Oct 8, 2:06 pm, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guard.caspershouse.comwrote:
Vinnie,
You could just create instances of the Attachment class, passing in the
InputStream property from the HttpPostedFile instance that corresponds to
the uploaded file (which you get from the collection exposed by the Files
property on the HttpRequest instance).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

Hi Nicholais, thanks for your help.

since it's my first time in writing a mail massege code, do you think
you can post a sample code that i can study and so apply to the form
i'm working on?

This is what's on the page:

To, From, Subject, Body of a mail message;
Upload-file field;
Submit button.

Thanks
What do you think about this:

/ get the name of the file, Upload is a control name
string fileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(@"C:\Website\" + fileName);

// then attach it
MailMessage msgMail = new MailMessage();
msgMail.Attachments.Add(new MailAttachment(@"C:\Website\" +
fileName));

Now, what happen if the webpage is on a ISP and not on my pc(is
published on internet)? how do i save the file on a virtual directory?

Thanks

Oct 8 '07 #4
vinnie,

You don't. You should get the file from the Files collection exposed by
the Request property on your page. Then, you can use the InputStream that
is returned form the HttpPostedFile instance, and pass that to the
constructor of your Attachment instance.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vinnie" <ce**********@gmail.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
On Oct 8, 2:25 pm, vinnie <centro.ga...@gmail.comwrote:
>On Oct 8, 2:06 pm, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guard.caspershouse.comwrote:
Vinnie,
You could just create instances of the Attachment class, passing in
the
InputStream property from the HttpPostedFile instance that corresponds
to
the uploaded file (which you get from the collection exposed by the
Files
property on the HttpRequest instance).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

Hi Nicholais, thanks for your help.

since it's my first time in writing a mail massege code, do you think
you can post a sample code that i can study and so apply to the form
i'm working on?

This is what's on the page:

To, From, Subject, Body of a mail message;
Upload-file field;
Submit button.

Thanks

What do you think about this:

/ get the name of the file, Upload is a control name
string fileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(@"C:\Website\" + fileName);

// then attach it
MailMessage msgMail = new MailMessage();
msgMail.Attachments.Add(new MailAttachment(@"C:\Website\" +
fileName));

Now, what happen if the webpage is on a ISP and not on my pc(is
published on internet)? how do i save the file on a virtual directory?

Thanks
Oct 8 '07 #5
On Oct 8, 2:54 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
vinnie,

You don't. You should get the file from the Files collection exposed by
the Request property on your page. Then, you can use the InputStream that
is returned form the HttpPostedFile instance, and pass that to the
constructor of your Attachment instance.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"vinnie" <centro.ga...@gmail.comwrote in message

news:11*********************@22g2000hsm.googlegrou ps.com...
On Oct 8, 2:25 pm, vinnie <centro.ga...@gmail.comwrote:
On Oct 8, 2:06 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Vinnie,
You could just create instances of the Attachment class, passing in
the
InputStream property from the HttpPostedFile instance that corresponds
to
the uploaded file (which you get from the collection exposed by the
Files
property on the HttpRequest instance).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Hi Nicholais, thanks for your help.
since it's my first time in writing a mail massege code, do you think
you can post a sample code that i can study and so apply to the form
i'm working on?
This is what's on the page:
To, From, Subject, Body of a mail message;
Upload-file field;
Submit button.
Thanks
What do you think about this:
/ get the name of the file, Upload is a control name
string fileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(@"C:\Website\" + fileName);
// then attach it
MailMessage msgMail = new MailMessage();
msgMail.Attachments.Add(new MailAttachment(@"C:\Website\" +
fileName));
Now, what happen if the webpage is on a ISP and not on my pc(is
published on internet)? how do i save the file on a virtual directory?
Thanks
Well, the code i told you about is the only one i found in internet.
And it doens;t work, actually.

Do you have a sample code i can study and so apply to the form?

Thanks

Oct 8 '07 #6
Hi,

A little addition.

Be aware that what Nicholas write is for the System.Net.Mail class which
started with version Net 2.0. For System.Web.Mail which is obsolete, however
the only one in Net 1.1, there is no property to use a stream in an
attachment. However you can do it using a temporaly file.

Cor
Oct 9 '07 #7

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

Similar topics

6
by: pee2pee | last post by:
Hi, I have below code: <html> <head> <title>Contacting Worldpay, Please wait.......</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body...
0
by: Merijn Boom | last post by:
Hi there, I'm trying to create an html mail with embedded pictures in it. I run perl on Windows and Red Hat but I cannot get your module (Mail::Sender) to work. I'm just trying to run the...
5
by: Eric Culus | last post by:
I seem to be having troubles with this page.... It's an automated mailing script... Steps: - system checks on x dates the variables linked to a maintenance contract (query on db) - when...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
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...
12
by: e_matthes | last post by:
Hello everyone, I am trying to use the mail() function to send a simple, text-only message. I have two websites hosted by the same company, on different servers. One is old and established,...
2
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....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.