Sending Image Through Mail in dot net

Method 1: Sending mail by directly giving the link in src:-

protected void mail_send(object sender, EventArgs e)

    {

        connectdb();

        string q = "select img from wedding_regdb where userid='" + TextBox1.Text + "'";

        cm = new SqlCommand(q, cn);

        dr = cm.ExecuteReader();

        if (dr.Read())

        {

            

            GridViewRow gr1 = ((Button)sender).NamingContainer as GridViewRow;

            Button b2 = (Button)gr1.FindControl("mailbtn");


            SmtpClient sm = new SmtpClient("student-cell.com", 25);

            sm.Credentials = new System.Net.NetworkCredential("contact@student-cell.com", "password");

            sm.DeliveryMethod = SmtpDeliveryMethod.Network;

            MailMessage mm = new MailMessage("contact@student-cell.com", gr1.Cells[2].Text);

            mm.Subject = "Invitation!!";

            mm.Body = @" Mr. Chitransh Thakur Invited You For The Weeding. <br />

            <img src=""http://student-cell.com/dotnet1/WeddingProject/upinvitation/upload/Wed.jpeg""/>";

            mm.IsBodyHtml = true;

            sm.Send(mm);

        }

    }


Method 2 : Storing Link in a Variable and pass it to src:-

 protected void mail_send(object sender, EventArgs e)

    {

        connectdb();

        string q = "select img from wedding_regdb where userid='" + TextBox1.Text + "'";

        cm = new SqlCommand(q, cn);

        dr = cm.ExecuteReader();

        if (dr.Read())

        {

            string place =  dr["img"].ToString();

            string link = "http://student-cell.com/dotnet1/WeddingProject/upinvitation/upload/" + place;

            GridViewRow gr1 = ((Button)sender).NamingContainer as GridViewRow;

            Button b2 = (Button)gr1.FindControl("mailbtn");


            SmtpClient sm = new SmtpClient("student-cell.com", 25);

            sm.Credentials = new System.Net.NetworkCredential("contact@student-cell.com", "password");

            sm.DeliveryMethod = SmtpDeliveryMethod.Network;

            MailMessage mm = new MailMessage("contact@student-cell.com", gr1.Cells[2].Text);

            mm.Subject = "Invitation!!";

            mm.Body = @"You are invited <br/>

                      <img src="+link+">";

            mm.IsBodyHtml = true;

            sm.Send(mm);

        }


Comments

Popular posts from this blog

Parameter Query

Final Project

Grid View Paging