Hi,
Try this.......
In your .aspx page, write the following code.
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Email :"></asp:Label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>Kavya</asp:ListItem>
<asp:ListItem>Bharathi</asp:ListItem>
<asp:ListItem>Govind</asp:ListItem>
<asp:ListItem>Sarath</asp:ListItem>
<asp:ListItem>Prabhu</asp:ListItem>
<asp:ListItem>Sreenath</asp:ListItem>
<asp:ListItem>MallaReddy</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" Text="Submit"
onclick="Button1_Click" />
Next, in the .aspx.cs file write the following code.
protected void Button1_Click(object sender, EventArgs e)
{
string s1 = string.Empty;
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
s1 = item.ToString();
MailMessage mm = new MailMessage();
mm.From = new MailAddress("smtpmail747@gmail.com");
mm.To.Add(new MailAddress(txtEmail.Text));
mm.Body = CheckBoxList1.Items.FindByValue(s1).ToString();
mm.IsBodyHtml = true;
SmtpClient s = new SmtpClient("smtp.gmail.com");
s.Port = 587;
s.EnableSsl = true;
s.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
s.Credentials = new System.Net.NetworkCredential("smtpmail747@gmail.com", "knowledgeinfote");
s.Send(mm);
Label1.Text = "Email Sent SucessFully.";
}
}
}
Its working.....
Mark as Answer if its helpful to you.........
Regards,
Shree M.
Kavya Shree Mandapalli
Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator