Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send muliple attachments with 1 email

Posted on 2007-03-24
2
Medium Priority
?
261 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 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