IT Community - Software Programming, Web Development and Technical Support

How to send mail with multiple attachments?

This is a discussion on How to send mail with multiple attachments? within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, How to Send Mail With Multiple Attachments?.....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-27-2008, 08:49 PM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile How to send mail with multiple attachments?

Hi,
How to Send Mail With Multiple Attachments?..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-27-2008, 10:07 PM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to send mail with multiple attachments?

Can u paste ur code here for single file attachement
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-30-2008, 10:17 PM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: How to send mail with multiple attachments?

Hi,
The code for attaching single mail is described below.For this include namespace using System.Net.Mail;

MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromTextBox.Text);
mail.To.Add(toTextBox.Text);
mail.Subject = subjectTextBox.Text;
mail.Body = messageTextBox.Text;
Attachment mailAttach = new Attachment(fileUpload1.PostedFile.FileName);
mail.Attachments.Add(mailAttach);
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
Response.Write("Mail has been sent Successfully");
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-01-2008, 01:47 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: How to send mail with multiple attachments?

email with multiple attachments


There are three things we need to do to be able to run this code and I'm going to assume that you will be trying out this code at home on a Windows desktop computer.
First, you need to create a virtual directory in IIS to host this web application and set write permission because we will be saving and deleting files that will be email attachments. In the virtual directory, create a folder called "attachments". This is where we will temporarily store the uploaded files to attach to the email.
The second thing to do is to make sure that the SMTP server is running and that it can relay mail. From the IIS MMC window, with "local computer" selected on the left, you should see the "Default SMTP Virtual Server", if not you need to install it. Right-click it, go into "Properties", the "Access" tab, and click the "Relay" button. With the "only the list below" radio button selected, you should see the local IP address: 127.0.0.1, if it's not there, you need to add it.
The last thing is to set up the SMTP server in the application. In the code, look for this line (line # 149):
SmtpMail.SmtpServer = "localhost"; You need to replace "localhost" with the name or IP address of your SMTP mail server. On a Windows desktop computer, "localhost" is the default value and usually works.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-01-2008, 01:50 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: How to send mail with multiple attachments?

Using the code

First of all, we create a new MailMessage object and we call it "email". Then we set the From, To, Subject and Body properties as well as the BodyFormatof of this object to the values on our web form.
// Create a new blank MailMessage
MailMessage email = new MailMessage ();

// Set the properties of the MailMessage to the
// values on the form
if (rblMailFormat.SelectedItem.Text == "text")
email.BodyFormat = MailFormat.Text;
else
email.BodyFormat = MailFormat.Html;
email.From = txtSender.Text;
email.To = txtReceiver.Text;
email.Subject = txtSubject.Text;
email.Body = txtBody.Text; Now for the meat and potatoes of this little web application; the following block of code checks the first of three Open File Dialogs of our web form (the Open File Dialog is an HTML File Field control to which we've added the runat="server" property). If there is a value, the file is uploaded, saved on the server, and added as an attachment to the email. The processing of the two other Open File Dialogs are just the same.
Collapse
// Beginning of attachments processing
// Check the first open file dialog for a value
if (ofdAttachment1.PostedFile != null)
{
// Get a reference to PostedFile object
HttpPostedFile ulFile = ofdAttachment1.PostedFile;
// Get size of the file
int nFileLen = ulFile.ContentLength;
// Make sure the size of the file is > 0
if( nFileLen > 0 )
{
// Get the file name
strFileName = Path.GetFileName(ofdAttachment1.PostedFile.FileNam e);
// Preced the file name with "attachments/" so
// the file is saved to our attachments directory
strFileName = "attachments/" + strFileName;
// Save the file on the server
ofdAttachment1.PostedFile.SaveAs(Server.MapPath(st rFileName));
// Create the email attachment with the uploaded file
MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
// Attach the newly created email attachment
email.Attachments.Add(attach);
// Store filename so we can delete it later
attach1 = strFileName;
}
} Then we send the email and finish by deleting the attachments.
// Set the SMTP server and send the email
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (email);

// Delete the attachements if any
if (attach1 != null)
File.Delete(Server.MapPath(attach1));referencehttp ://www.codeproject.com/aspnet/ASPNETwebmail.asp
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-01-2008, 03:07 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: How to send mail with multiple attachments?

Hi,
i think u have used System.web.Mail; namespace.But If i use this,it throws a error message to include namespace System.Net.Mail;for ASP.Net2.0.I have problem while sending mail using the following lines,

SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (email)
;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we send mail using JavaScript? sundarraja PHP Programming 2 01-22-2008 03:57 AM
How to Send mail using dot net ...? a.deeban ASP and ASP.NET Programming 9 01-17-2008 09:20 PM
send the sms using SMS/MMS Gateway in php varghese PHP Programming 1 09-18-2007 08:32 AM
How can we send mail using JavaScript? Sabari HTML, CSS and Javascript Coding Techniques 3 09-12-2007 12:33 AM
How to Send Mail Using Stored Procedure in MS SQL SERVER 200x?? Gopisoft Database Support 1 07-17-2007 09:43 AM


All times are GMT -7. The time now is 06:51 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0