c# - 向新用户 aspx 发送自动电子邮件

标签 c# asp.net

当有人在我的网站上注册时,他/她还需要填写他/她的电子邮件地址。

点击“注册”按钮后,系统需要向文本框中写入的电子邮件地址发送一封自动电子邮件。

谁能帮我解决这个问题?

提前致谢!

最佳答案

要在 ASP.NET 中发送电子邮件,您需要查看 System.Net.Mail。有两个步骤可以从 ASP.NET 中发送邮件

1) 电子邮件帐户设置 - 可以在您的 web.config 文件中进行全局设置

<system.net>
    <mailSettings>
      <smtp from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="552130262115333a3a7b363a38" rel="noreferrer noopener nofollow">[email protected]</a>">
        <network host="host" port="25" userName="username" password="password" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

2) 设置您的消息 - 在您的注册页面代码后面

MailMessage message = new MailMessage();
message.From = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e4f2f9f3f2e5d7e4f2f9f3f2e5b9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>");

message.To.Add(new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb9e969a9297bb9e969a9297d5989496" rel="noreferrer noopener nofollow">[email protected]</a>"));

message.Subject = "subject";
message.Body = "content";

SmtpClient client = new SmtpClient();
client.Send(message);

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx

关于c# - 向新用户 aspx 发送自动电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525806/

相关文章:

.NET 4 中的 C# 代码生成

asp.net - 搜索 elmah 错误日志文件(可能是 1000 年)

c# - 使用计时器显示文本 3 秒?

c# - 动态添加WCF服务的引用

C# 初学者 - 在同一个函数中回调

c# - 传入字典的模型项在 ASP.net MVC 中属于“System.Collections.Generic.List...”类型

c# - 为什么我在 VS 2010 中出现奇怪的索引错误?

c# - 如何检测滚动条何时到达数据 GridView 的末尾?

asp.net - 有没有办法向 ASP.NET Label 服务器控件添加 onclick 事件?

.net - 在午夜或没有分钟和秒时获取今天的日期