用户输入数据时如何发送邮件 [英] How to send mail's when user input the data
本文介绍了用户输入数据时如何发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请在下面找到我的要求并帮帮我..
我的前端有一些文本字段,例如名称,资格,DOB,地址等...带有提交按钮.
&我有包含mailID的数组
现在我的要求是,当用户单击提交"按钮时,应使用上述数组中的所有mailID..
Hi,
Please find my requirement below & help me out..
I have front end with some textfields like name, qualification, DOB, Address etc... with submit button.
& I have array which contains mailID''s
Now my requirement is When the user clicks submit button the should be delievered to all mailID''s which are in the above array..
How can i do this?
推荐答案
在提交"按钮上尝试以下代码..
受保护的无效btnSendmail_Click(对象发送者,EventArgs e)
{
//System.Web.Mail.SmtpMail.SmtpServer在2.0中已过时
//System.Net.Mail.SmtpClient是2.0中的替代类
SmtpClient smtpClient =新的SmtpClient();
System.Web.Mail.MailMessage消息=新的System.Web.Mail.MailMessage();
试试
{
MailAddress fromAddress = new MailAddress("admin1@yoursite.com","Hrushi");
//您可以指定服务器的主机名或IP地址
//IIS中的默认值为localhost
smtpClient.Host =本地主机";
//默认端口为25
smtpClient.Port = 25;
//发件人地址将作为MailAddress对象给出
message.From = fromAddress;
//处理MailAddress的地址集合
message.Subject =反馈";
//CC和BCC可选
//MailAddressCollection类用于将电子邮件发送给各个用户
//您可以将地址指定为新的MailAddress("admin1@yoursite.com")
message.CC.Add("admin1@yoursite.com");
//正文可以是HTML或文本格式
//如果是html消息,则指定true
message.IsBodyHtml = false;
//消息正文
message.Body ="name =" + name.Text +,资格= + + qualification.Text +",DOB ="+ DOB.Text +",Address ="+ Address.Text +";
foreach(_arrayObject中的var _ToAdd)
{
message.To.Add(_ToAdd.ToString());
//发送SMTP邮件
smtpClient.Send(消息);
}
lblStatus.Text =电子邮件发送成功.";
}
catch(ex ex例外)
{
lblStatus.Text =发送电子邮件失败." + ex.Message;
}
}
try the following code at your Submmit button..
protected void btnSendmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
try
{
MailAddress fromAddress = new MailAddress("admin1@yoursite.com", "Hrushi");
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "localhost";
//Default port will be 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.Subject = "Feedback";
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
message.CC.Add("admin1@yoursite.com");
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
//Message Body
message.Body = "name=" + name.Text + ", qualification=" + qualification.Text + ", DOB=" + DOB.Text + ", Address=" + Address.Text + "";
foreach (var _ToAdd in _arrayObject)
{
message.To.Add(_ToAdd.ToString());
// Send SMTP mail
smtpClient.Send(message);
}
lblStatus.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblStatus.Text = "Send Email Failed." + ex.Message;
}
}
这篇关于用户输入数据时如何发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文