要向c#中的所有ID文本框发送电子邮件 [英] To send email to all ID's of textbox in c#
本文介绍了要向c#中的所有ID文本框发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过检查电子邮件语法将电子邮件发送到textfield的所有条目作为电子邮件ID,这是
解决方案
的c#代码hi
尝试这段代码...
它可能对你有所帮助..
将所有文本控件放在一个集装箱控制。 as
< div id = divContainer runat = 服务器 >
< asp:TextBox ID = TextBox1 runat = server > < / asp: TextBox >
< asp:TextBox ID = TextBox2 runat = server > < / asp:TextBox >
'
'
'
< asp:TextBox ID = TextBox20 r unat = server > < / asp:TextBox >
< / div >
代码落后:
protected void Button1_Click( object sender,EventArgs e)
{
foreach ( var item in divContainer.Controls)
{
if (item TextBox)
{
string email =(item as TextBox).Text;
if (CheckValidEmailAddress(email))
{
// 发送电子邮件代码块。
}
}
}
}
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 正则表达式(模式);
return regularExpression.IsMatch(emailID);
}
嗨Sachin,
会更好如果你问了样本输入的问题。
让我们猜你有用逗号(,)分隔符分隔的电子邮件列表
txtbox1.Text = @ test @ test.com,abc @ abc.com,amigo @ amigo.com,def @ def.com ,休息@ rest.com跨度>;
string [] emailid = txtbox1.Text.Split( new string [] { ,},StringSplitOptions.RemoveEmptyEntries);
foreach ( var 电子邮件在 emailid)
{
// 每封电子邮件都会发送电子邮件代码id
}
注意:如果您使用分号作为分隔符,则在分割函数中将逗号更改为分号。
希望这对你有所帮助。
问候,
RK
How can i send email to all entries of textfield as email id by checking email syntax,waht is C# code for this
解决方案
hi Try this code...
It might help you..
Place all your text controls in a container control. as
<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:
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); }
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
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
这篇关于要向c#中的所有ID文本框发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文