Solved

Send muliple attachments with 1 email

Posted on 2007-03-24
2
245 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now