Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to save images to the database and that images can be loaded to user created folder,then we have to select the image and send to the mail.
I use the following code,

C#
protected void Upload_Click(object sender, EventArgs e)
   {
       String s = (String)Session["temp"];
       if (FileUpload1.HasFile)
       {
           // string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
           // FileUpload1.PostedFile.SaveAs(Server.MapPath("~/" + s + "\\") + fileName);

           string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
           path = Server.MapPath("~/" + s + "\\") + fileName;
           FileUpload1.SaveAs(path);                                         
           Response.Redirect(Request.Url.AbsoluteUri);                                insert imges
           // Session["PATH"] = path;

       }




protected void Send_Click(object sender, EventArgs e)
    {
        String sndps=(String)Session["pswd"];
        // String s = (String)Session["PATH"];
        String s = (String)Session["temp"];
        String em = (String)Session["email"];
        //TextBox1.Text = em;
        MailMessage msg = new MailMessage();
        string ActivationUrl = string.Empty;
        string emailid = string.Empty;
        SmtpClient smtp = new SmtpClient();
        string emailId = em;
        msg.From = new MailAddress("a@gmail.com");
        msg.To.Add(em);
        msg.Subject = "Conformation mail";
        msg.Body ="Your Login Password is:"+sndps;
        msg.IsBodyHtml = true;
       // string[] files = Directory.GetFiles(path);
        /*foreach (string file in files)
        {
            Console.WriteLine(file);                           
        }*/

        // msg.Attachments.Add( files);
        //new Attachment(files));
        //// if (FileUpload1.HasFile)
        //// {
        // msg.Attachments.Add(new Attachment(files.));
        //// }



        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential("a@gmail.com", "r");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(msg);
        Response.Write("msg snd........");


        //Session["temp1"] = Usernametxt.Text;
        //Session["temp2"] = emailtxt.Text;
        //Response.Redirect("http://localhost:62874/MapExtractor/MsgSendPage.aspx");




    }
Posted
Updated 25-Aug-14 0:09am
v2
Comments
Ashi0891 25-Aug-14 6:23am    
where is the problem? while storing image in database or in sending mail?
Reshma CS 25-Aug-14 6:33am    
attaching images to the mail,with out using file upload

1 solution

 
Share this answer
 

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