Click here to Skip to main content
16,011,804 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
How can i send email to all entries of textfield as email id by checking email syntax,waht is C# code for this
Posted
Comments
Vishal Pand3y 13-Dec-13 5:20am    
it will be better to split the EmailIds by , or ;

hi Try this code...
It might help you..


Place all your text controls in a container control. as

XML
<div id="divContainer" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        '
        '
        '
        <asp:TextBox ID="TextBox20" runat="server"></asp:TextBox>


    </div>



Code behind:


C#
protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (var item in divContainer.Controls)
            {
                if (item is TextBox)
                {
                    string email = (item as TextBox).Text;
                    if (CheckValidEmailAddress(email))
                    {
                        // send email code block.

                    }
                }
            }
        }
        public static bool CheckValidEmailAddress(string emailID)
        {
            string pattern = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex regularExpression = new Regex(pattern);
            return regularExpression.IsMatch(emailID);

        }
 
Share this answer
 
Hi Sachin,

It will be better if you have asked question with sample input.
Lets guess you have list of email separated with comma(,) delimiter
C#
txtbox1.Text = @"test@test.com,abc@abc.com,amigo@amigo.com,def@def.com,rest@rest.com";
            string[] emailid = txtbox1.Text.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var email in emailid)
            {
                //Send email code comes here for every email id
            }

Note: If you have used semicolon as delimiter then change comma to semicolon in split function.
Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v2

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