complete message

  • Thread starter Thread starter Vinnie
  • Start date Start date
V

Vinnie

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
 
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

MailMessage msgMail = new MailMessage();
msgMail.Attachments.Add(new MailAttachment("c:\\temp\\annual-
report.pdf"));
 
MailMessage msgMail = new MailMessage();
msgMail.Attachments.Add(new MailAttachment("c:\\temp\\annual-
report.pdf"));

hi Alexey thanks,
but how do i relate this attachment to the mail that the user is now
sending me?
I mean, if on a webpage there is a form to send an email message to
the webmaster, and is available the option to upload a file and attach
it to this mail, how can this should be coded? (because if the user
upload a file, i don't know the name of that file)

Thanks
 
hi Alexey thanks,
but how do i relate this attachment to the mail that the user is now
sending me?
I mean, if on a webpage there is a form to send an email message to
the webmaster, and is available the option to upload a file and attach
it to this mail, how can this should be coded? (because if the user
upload a file, i don't know the name of that file)

Thanks

it's pretty easy, you save the file and attach to a message

For example (c#):

// 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));
.....

Look at the following article, I think it does more or less the same
thing
http://www.codeproject.com/useritems/Email_Application.asp
 
it's pretty easy, you save the file and attach to a message

For example (c#):

// 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));
....

Look at the following article, I think it does more or less the same
thinghttp://www.codeproject.com/useritems/Email_Application.asp

Cool! thanks Master :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top