I am doing a small project.In that users can register for yoga programs.When the administrator set the new program with date ,place and timings then the registered users should get email automatically with all above details .
Please help me doing this.
I have done the registration part successfully.

Hi,
Pretty big topic to post here but I'll try to explain it in brief:

I'm guessing you want some event (a new yoga class being set up) to trigger the email part of the software. Thats simple enough, it can be user controlled or called when the new yoga class is saved, created, etc.

To send the emails you will want to pull all of the relevant users and their email address out of your database. Store this in a dataTable or similar.

For the emails you could choose to send an email to each person seperately (have one name in the To field when the user receives the email); to do this call the email sending method once for every name in the dataTable of users. This is pretty wasteful unless you have an idle server and load isn't an issue. You can personalise the email with this method i.e. use the person's name directly.

Option two is to concatenate all the user's emails into a string and call the email method once; all the users appear in the To field and you wouldn't be able to personalise the email.

The email method itself will need to import the System.Mail class (I think thats what its called) and set up the To, From, Message, etc parts of the email; and then send it. The MSDN library will have everything you need to set it up.

OK, thats the theory, hope it helps.

ThankU sir,
I need to include the place,time and date of the new yoga program (which are stored in a program table )as the body of the message.Please provede coding in c#.

Thank U for your reply.
Can U please provide coding in c# for option two of your reply.

Hi,
try this code

protected void btn_clk(object s,eventargs e)
{
       sqlcommand cmd=new sqlcommand("select email from  
       usertable",connectionstring)
        string email;
       sqldatareader dr=cmd.executereader();

       while(dr.read())
       { 
           email=dr[0];
           SmtpClient c = new SmtpClient(yourIPAddress);

            MailAddress addr = new            
            MailAddress(fromaddress);

            MailAddress add = new  
            MailAddress(email); 

            MailMessage msg = new MailMessage();
           msg.To.Add(add);
           msg.From = addr;
           msg.IsBodyHtml = true;
           msg.Body="<html><body>Place:Hyderabad"+<br>"+"Time:</body></html>";
    c.Send(msg);
       }


}

if the place and time are stored in a table,the just write a query to retrieve the place and time in the click event ,store them in variables and pass them in the body of the mail as

msg.Body="place:"+placevariable+"Time:"+timevariable;

All the best

Thank U very much praveen.
Is it possible to send more than one mail( to different addresses and same body of message)using the above code.How to separate those addresses with comma(,).
please Reply me soon

Hi,
The mail generation code is inside a loop,so it will obviously send a mail to all the users with the same message body.

Thank you,
regards

Hi Praveen,
I got the Exception(inner exception)
{"Unable to connect to the remote server"}
How to handle this.
please reply soon.
Thank U.

Hi,
Please send ur entire code.

regards

Hi,
The below code i have given in Button_click event

protected void Button1_Click(object sender, EventArgs e)
    {
         string place;
        string Session;
        string sdate;
        string duration;
       DataSet dst = new DataSet();
        con = new SqlConnection("Persist Security Info=False;Uid=sa;Password=q1w2e3/;Initial Catalog=YOGADATA;Data Source=PC-1");
        SqlCommand com = new SqlCommand("insertrecordspro", con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add(new SqlParameter("@Pid", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Name", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@Place", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@Session", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Trainer", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Duration", SqlDbType.NChar, 10));

        com.Parameters["@Name"].Value = DropDownList1.SelectedItem.ToString();
        com.Parameters["@Place"].Value = DropDownList2.SelectedItem.ToString();
        com.Parameters["@Session"].Value = DropDownList3.SelectedItem.ToString();
        com.Parameters["@Trainer"].Value = DropDownList4.SelectedItem.ToString();
        com.Parameters["@StartDate"].Value = TextBox2.Text.ToString();
        com.Parameters["@Duration"].Value = TextBox1.Text.ToString();
        place = DropDownList2.SelectedItem.ToString();
        Session = DropDownList3.SelectedItem.ToString();
        sdate = TextBox2.Text.ToString();
        duration = TextBox1.Text.ToString();
        DataSet dst1 = new DataSet();
        SqlDataAdapter adp1 = new SqlDataAdapter("select Pid from Program", con);
        adp1.Fill(dst1, "Program");
        DataTable dt = new DataTable();
        DataRow[] dr = new DataRow[100];
        dt = dst1.Tables["Program"];
        String id;
        id = dt.Rows[dt.Rows.Count - 1]["Pid"].ToString();
        string str;
        str = id.Substring(1,3);
        int y;
        y = System.Convert.ToInt16(str);
        y = y + 1;
        if (y > 1 && y <= 9)
        {
            com.Parameters["@Pid"].Value = "S00" + y;
        }
        if (y > 9 && y <= 99)
        {
            com.Parameters["@Pid"].Value = "S0" + y;
        }
        if (y > 99 )
        {
            com.Parameters["@Pid"].Value = "S" + y;
        }


        try
        {
            com.Connection.Open();
            com.ExecuteNonQuery();
        }
        catch (System.FormatException exc)
        {
            Lblmsg.Text = "Source:" + exc.Source;
        }
        SqlCommand com1 = new SqlCommand("select EmailID from Student where (Status=1) or (Status=2) or (Status=3)", con);
        String email;
        SqlDataReader dtr = com1.ExecuteReader();
        while (dtr .Read ())
        {
            SmtpClient c = new SmtpClient("192.168.1.2");
            email = dtr[0].ToString();
            MailMessage msg = new MailMessage();
            MailAddress fadd=new MailAddress ("vr75@rediffmail.com");
            MailAddress tadd=new MailAddress (email);

            msg.From = fadd;
            msg.To.Add(tadd);
            msg.Body = "Our New Program Details are" + "   " + "Place is" + place + "    " + "Session is" + Session + "    " + "Starting Date is" + sdate + "    " + "Duration is" + duration;
            msg.Subject = "New Yoga Program";
            //try
            //{
                c.Send(msg);
            //}
            //catch (Exception exc)
            //{
            //    Lblmsg.Text = "Source:" + exc.Source;
            //}


        }
        Lblmsg.Visible = true;
        Lblmsg.Text = "New Progam is updated successfully";
    }
}
commented: Code tag please. See announcement link at top of each forum. -3

The below code i have given in Button_click event

protected void Button1_Click(object sender, EventArgs e)
    {
         string place;
        string Session;
        string sdate;
        string duration;
       DataSet dst = new DataSet();
        con = new SqlConnection("Persist Security Info=False;Uid=sa;Password=q1w2e3/;Initial Catalog=YOGADATA;Data Source=PC-1");
        SqlCommand com = new SqlCommand("insertrecordspro", con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add(new SqlParameter("@Pid", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Name", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@Place", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@Session", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Trainer", SqlDbType.NChar, 20));
        com.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.NChar, 10));
        com.Parameters.Add(new SqlParameter("@Duration", SqlDbType.NChar, 10));

        com.Parameters["@Name"].Value = DropDownList1.SelectedItem.ToString();
        com.Parameters["@Place"].Value = DropDownList2.SelectedItem.ToString();
        com.Parameters["@Session"].Value = DropDownList3.SelectedItem.ToString();
        com.Parameters["@Trainer"].Value = DropDownList4.SelectedItem.ToString();
        com.Parameters["@StartDate"].Value = TextBox2.Text.ToString();
        com.Parameters["@Duration"].Value = TextBox1.Text.ToString();
        place = DropDownList2.SelectedItem.ToString();
        Session = DropDownList3.SelectedItem.ToString();
        sdate = TextBox2.Text.ToString();
        duration = TextBox1.Text.ToString();
        DataSet dst1 = new DataSet();
        SqlDataAdapter adp1 = new SqlDataAdapter("select Pid from Program", con);
        adp1.Fill(dst1, "Program");
        DataTable dt = new DataTable();
        DataRow[] dr = new DataRow[100];
        dt = dst1.Tables["Program"];
        String id;
        id = dt.Rows[dt.Rows.Count - 1]["Pid"].ToString();
        string str;
        str = id.Substring(1,3);
        int y;
        y = System.Convert.ToInt16(str);
        y = y + 1;
        if (y > 1 && y <= 9)
        {
            com.Parameters["@Pid"].Value = "S00" + y;
        }
        if (y > 9 && y <= 99)
        {
            com.Parameters["@Pid"].Value = "S0" + y;
        }
        if (y > 99 )
        {
            com.Parameters["@Pid"].Value = "S" + y;
        }


        try
        {
            com.Connection.Open();
            com.ExecuteNonQuery();
        }
        catch (System.FormatException exc)
        {
            Lblmsg.Text = "Source:" + exc.Source;
        }
        SqlCommand com1 = new SqlCommand("select EmailID from Student where (Status=1) or (Status=2) or (Status=3)", con);
        String email;
        SqlDataReader dtr = com1.ExecuteReader();
        while (dtr .Read ())
        {
            SmtpClient c = new SmtpClient("192.168.1.2");
            email = dtr[0].ToString();
            MailMessage msg = new MailMessage();
            MailAddress fadd=new MailAddress ("vr75@rediffmail.com");
            MailAddress tadd=new MailAddress (email);

            msg.From = fadd;
            msg.To.Add(tadd);
            msg.Body = "Our New Program Details are" + "   " + "Place is" + place + "    " + "Session is" + Session + "    " + "Starting Date is" + sdate + "    " + "Duration is" + duration;
            msg.Subject = "New Yoga Program";
            //try
            //{
                c.Send(msg);
            //}
            //catch (Exception exc)
            //{
            //    Lblmsg.Text = "Source:" + exc.Source;
            //}


        }
        Lblmsg.Visible = true;
        Lblmsg.Text = "New Progam is updated successfully";
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.