如何在选中复选框时发送电子邮件 [英] how to send email on selecting the check box
本文介绍了如何在选中复选框时发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在选中复选框时发送电子邮件
解决方案
使用复选框checkedchanged事件的回发。然后使用system.net.mail中的普通smtp客户端发送电子邮件!
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checkedchanged.aspx [ ^ ]
放置复选框AutoPostBack = true
< asp:checkbox id = checkbox1 runat = server xmlns:asp = #unknown >
AutoPostBack = True /> ; < / asp:复选框 >
然后在代码块内写入
if (checkbox1.Checked == true )
{
// 调用方法发送邮件
}
发送邮件链接
在ASP中发送电子邮件.Net 2.0 - 反馈表格 [ ^ ]
试试这样
< span class =code-keyword> if (checkbox1。 checked == true )
{
尝试
{
MailAddress fromAddress = new MailAddress(txtEmail.Text,txtName.Text);
smtpClient.Host = localhost;
smtpClient.Port = 25 ;
message.From = fromAddress; message.To.Add( 123@gmail.com); // 此处您必须传递复选框文本或toaddress
message.Subject = Hello;
message.IsBodyHtml = false ;
message.Body = pswd;
smtpClient.Send(message);
Label1.Text = 电子邮件已成功发送。;
}
}
或
protected void CheckBox1_CheckedChanged( object sender,EventArgs e)
{
// 在此处写邮件代码
}
how to send email on selecting the check box
解决方案
use the postback of the checkbox checkedchanged event. Then send an email using the normal smtp client from system.net.mail!
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checkedchanged.aspx[^]
Put check box AutoPostBack=true
<asp:checkbox id="checkbox1" runat="server" xmlns:asp="#unknown"> AutoPostBack="True" /></asp:checkbox>
Then inside code block write
if(checkbox1.Checked==true) { //call method for sending mail }
Send mail link
Send Email in ASP.Net 2.0 - Feed back Form[^]
try like this
if( checkbox1.checked==true) { try { MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text); smtpClient.Host = "localhost"; smtpClient.Port = 25; message.From = fromAddress; message.To.Add("123@gmail.com");//here you have to pass checkbox text or toaddress message.Subject = "Hello"; message.IsBodyHtml = false; message.Body = pswd; smtpClient.Send(message); Label1.Text = "Email successfully sent."; } }
or
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { //write mail code here }
这篇关于如何在选中复选框时发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文