当有人在我的网站上注册时,他/她还需要填写他/她的电子邮件地址。
点击“注册”按钮后,系统需要将自动发送的电子邮件发送到文本框中写的电子邮件地址。
有谁可以帮我解决这个问题?
提前致谢!
答案 0 :(得分:2)
要在asp.net中发送电子邮件,您需要查看System.Net.Mail。有两个步骤,两个从asp.net
发送邮件1)电子邮件帐户设置 - 可以在web.config文件中全局设置
<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="host" port="25" userName="username" password="password" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
2)设置信息 - 在您的注册页面代码
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@sender.com");
message.To.Add(new MailAddress("email@email.com"));
message.Subject = "subject";
message.Body = "content";
SmtpClient client = new SmtpClient();
client.Send(message);
http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
答案 1 :(得分:1)
以下是有关如何从.NET代码发送电子邮件的简单说明:http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
您要查找的主要关键字是System.Net.Mail
。
答案 2 :(得分:1)
以下脚本是一个很好的起点。
using (System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage()) {
System.Text.StringBuilder body = new System.Text.StringBuilder("Your message");
System.Net.Mail.SmtpClient() smtp = new System.Net.Mail.SmtpClient();
mail.To.Add("yourUser@email.com");
mail.From = new System.Net.Mail.MailAddress("yourFrom@email.com");
mail.Subject = "a Subject";
mail.Body = body.ToString();
try {
smtp.Send(mail);
} catch (Exception ex) {
// handle your exception here..
}
}
这假设您的配置中有关于SmtpClient的一些详细信息。像这样:http://msdn.microsoft.com/en-us/library/ms164240.aspx
如果没有,那么您可以在SmtpClient()
构造函数中向客户提供详细信息。有关详细信息,请访问:http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
答案 3 :(得分:1)
这是一个简单的实现功能。如果不是匿名和SMTP中继服务器的SMTP信息,则必须获取网络凭据。否则它应该是直截了当的。
using System.Net.Mail; //goes on top
//goes in your class
public void sendEmail(string emailMessage,
string emailSubject,
string emailAddress, string from,
string fromAddress, string emailCC,
string emailBCC)
{
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromAddress, from);
msg.To.Add(emailAddress);
if (emailCC != null && emailCC.ToString().Length > 1)
msg.CC.Add(emailCC);
if (emailBCC != null && emailBCC.ToString().Length > 1)
msg.Bcc.Add(emailBCC);
msg.Priority = MailPriority.High;
msg.Subject = emailSubject;
msg.Body = emailMessage;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = info.SMTPServer;
client.Port = 25;
client.EnableSsl = true;
// client.UseDefaultCredentials = some System.Net.NetworkCredential var;
client.Credentials = info.networkCredentials;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
// Use SendAsync to send the message asynchronously
client.Send(msg);
}
catch
{
//handle exception
}
}
USAGE&amp;实现:
this.sendEmail("test message", "your subject", "to@to.com","from person", "from@from.com","cc@cc.com","bcc@bcc.com");