Solved

Send muliple attachments with 1 email

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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