如何从ASP.Net应用程序发送电子邮件 [英] how to send an email from ASP.Net appliaction
本文介绍了如何从ASP.Net应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从ASP.Net应用程序发送电子邮件?
请给我示例代码.
how to send an email from ASP.Net appliaction??
Please give me sample code for that.
推荐答案
请参阅以下链接:
如何通过asp.net发送电子邮件 [ ^ ]
Refer this link:
How to send email through asp.net[^]
没有人会为您提供任务的示例代码.看看 ^ ],以获得大量文章或获得帮助的代码.
No one will give you sample code for your task. have a look there-[send email using asp.net ][^] for plenty of article or codes for getting help.
尝试一下,
Try this,
Using system.net.Mail
Enter Email :<asp:textbox id="txtEmail" runat="server" xmlns:asp="#unknown"></asp:textbox><br />
<asp:button id="btnSubmit" runat="server" xmlns:asp="#unknown" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
String strEmail,strFrom,strTo,strSubject,strBody;
strEmail= txtEmail.Text.ToString();
strTo = ConfigurationManager.AppSettings["RequestEmail"].ToString();
strSubject = "News letter subscription";
strBody = "Email = "+ strEmail.ToString();
strEmail = Trim(txtEmail.Text);
MailMessage objmail=new MailMessage();
objmail.From = strEmail;
objmail.To.Add(strTo);
objmail.Subject = strSubject;
objmail.Body = strBody;
objmail.IsBodyHtml = True;
SmtpMail = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer"].ToString());
SmtpMail.Send(objmail);
}
在 web.config中,
In web.config,
//Give the ToEmail address .To which you need to send a mail
<add key="RequestEmail" value="test@maildomain.com" />
//Give the server(domain name) in value
<add key="SmtpServer" value="Smptp server name" />
希望对您有所帮助.
Hope it helps..
这篇关于如何从ASP.Net应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文