Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Now my website has a mail sending page.This mail sending function need a mail attachment , file take from local machine. How is it?
Posted
Updated 22-Jun-11 2:59am
v2

Please check this link:

ASP.NET email with multiple attachments[^]
 
Share this answer
 
v3
this code on your button ok

 protected void Button1_Click(object sender, EventArgs e)<br />
    {<br />
        SmtpClient smtpClient = new SmtpClient("smtp.paramtel.com");<br />
        MailMessage message = new MailMessage();<br />
        try<br />
        {<br />
            <br />
            MailAddress fromAddress = new MailAddress(TextBox1.Text.Trim());<br />
            smtpClient.Host = "localhost";<br />
            smtpClient.Port = 25;<br />
            message.From = fromAddress;<br />
            message.To.Add("deepak@domainname.com");<br />
            message.Subject = "query";<br />
            message.CC.Add("admin2@yoursite.com");<br />
            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);<br />
            Attachment myAttachment =<br />
                           new Attachment(FileUpload1.FileContent, fileName);<br />
            message.Attachments.Add(myAttachment);<br />
            message.IsBodyHtml = false;<br />
            message.Body = TextBox3.Text;<br />
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;<br />
            smtpClient.Send(message);<br />
            Label4.Text = "Email successfully sent.";<br />
        }<br />
        catch (Exception ex)<br />
        {<br />
            Label4.Text = "Send Email Failed.<br>" + ex.Message;<br />
        }<br />
<br />
        <br />
       <br />
    }<br />
 
Share this answer
 
Comments
fjdiewornncalwe 22-Jun-11 8:59am    
Just a note: When an OP is clearly asking us to do their homework for them, please refrain from giving them the code directly. As the other answers show, just guide them to where they can learn from. They learn nothing from a code dump.
Sergey Alexandrovich Kryukov 22-Jun-11 14:32pm    
Agree! It does not really help.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900