Solved

Send muliple attachments with 1 email

Posted on 2007-03-24
2
258 Views
Last Modified: 2010-04-16
Hi
Can anyone tell me how i can change the code below, so that it can send 3 attachments.

<form id="form1" runat="server">
    <div>
      <asp:FileUpload ID="FileUpload1" runat="server" />
      <asp:FileUpload ID="FileUpload2" runat="server" />
      <asp:FileUpload ID="FileUpload3" runat="server" />
      <asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" /></div>
  </form>

protected void Button1_Click(object sender, EventArgs e)
    {
    if (FileUpload1.HasFile)
        {
        string toAddress = "**@**";
        string fromAddress = "you@yourprovider.com";
        string mailServer = "smtp.**.**";

        MailMessage myMailMessage = new MailMessage();

        myMailMessage.To.Add(toAddress);
        myMailMessage.From = new MailAddress(fromAddress);
        myMailMessage.Subject = "Test Message";

        string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        Attachment myAttachment = new Attachment(FileUpload1.FileContent, fileName);
        myMailMessage.Attachments.Add(myAttachment);

        SmtpClient mySmtpClient = new SmtpClient(mailServer);

        mySmtpClient.Send(myMailMessage);
        }
    }
Regards
George
0
Comment
Question by:LearningCSharpSQL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
sumix earned 500 total points
ID: 18785024
just create two more instances of Attachment class and add the to myMailMessage.Attachments collection. So, after you add first attachment:

        fileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
        myAttachment = new Attachment(FileUpload2.FileContent, fileName);
        myMailMessage.Attachments.Add(myAttachment);

        fileName = Path.GetFileName(FileUpload3.PostedFile.FileName);
        myAttachment = new Attachment(FileUpload3.FileContent, fileName);
        myMailMessage.Attachments.Add(myAttachment);
0
 

Author Comment

by:LearningCSharpSQL
ID: 18785048
Hi sumix:
Perfect
Thanks
George
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question