Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my winforms application,i created a winform to send EmailNow i want to attach a file(image,doc or other file) with this mail and send this file. How can i perform this?Code is here:
C#
using System.Net;
using System.Net.Mail;

private void button1_Click(object sender, EventArgs e)
        {
             try
            {
                
                string idfrom = textBox1.Text;
                String password = textBox2.Text;
                String idto = textBox3.Text;
                string msg = richTextBox1 .Text ;
                string sub = textBox4.Text;
                var smtp = new SmtpClient();
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(idfrom,password);
                    smtp.Timeout = 20000;
                }
                smtp.Send(idfrom, idto, sub , msg);
                MessageBox.Show("Message has been sent");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message );
            }        
        }

Thanks
Posted
Updated 10-Oct-13 22:47pm
v2

1 solution

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