Solved

Send muliple attachments with 1 email

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2 questions 10 30
Latest thoughts on C# utilizing Mono on Linux vs .NET on Windows? 5 66
JQuery Detecting page post back 6 13
itextsharp with c# 3 10
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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