how to send mail in a sequece in asp.net

Discussion in 'C#' started by alamlinks, Sep 28, 2012.

  1. #1
    The answer is as below:

    string strTo = txtTo.Text;
    for (int i = 0; i < strTo.Split(',').Length;i++ )
    {
    string strMailId = strTo.Split(',');
    try
    {
    MailMessage msg = new MailMessage();
    msg.From = txtFrom;
    msg.To=txtTo;
    msg.Subject = txtSubject.Text;
    msg.IsBodyHtml = true;
    msg.Body = txtMail.Text;
    msg.Priority = MailPriority.High;

    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("xxx@gmail.com", "xxx"); //Email and Password

    client.EnableSsl = true;

    client.Send(
    msg );

    ScriptManager.RegisterStartupScript(btnSend, typeof(Page), "Confirm", "alert('Your enquiry sent successfully!');formReset();", true);
    }
    catch (Exception Ex)
    {
    ScriptManager.RegisterStartupScript(btnSend, typeof(Page), "Error:", "alert('Oops! Some error occoured.')", true);
    }
    }
    For more knowledge go through http://failuredeveloper.blogspot.com/


    Thanks & Regfards
     
    alamlinks, Sep 28, 2012 IP