发送电子邮件asp.net c#

可以使用C#中的asp.net项目从我的电脑(localhost)发送电子邮件吗?
最后我要将我的项目上传到webserver,但我想在上传之前进行测试.

我已经找到了准备好的源代码,并尝试在本地主机中运行它们,但是它们都不成功.
例如这个代码

using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net.Mail;

    namespace sendEmail
    {
        public partial class _default : System.Web.UI.Page
        {
            protected void Page_Load(object sender,EventArgs e)
            {

            }
            protected void Btn_SendMail_Click(object sender,EventArgs e)
            {
                MailMessage mailObj = new MailMessage(
                    txtFrom.Text,txtTo.Text,txtSubject.Text,txtBody.Text);
                SmtpClient SMTPServer = new SmtpClient("localhost");
                try
                {
                    SMTPServer.Send(mailObj);
                }
                catch (Exception ex)
                {
                    Label1.Text = ex.ToString();
                }
            }
        }
    }

那么如何使用asp.net C#发送电子邮件?我应该设置一些服务器配置吗?

解决方法

从Asp.Net发送电子邮件
MailMessage objMail = new MailMessage("Sending From","Sending To","Email Subject","Email Body");
    NetworkCredential objNC = new NetworkCredential("Sender Email","Sender Password");
    SmtpClient objsmtp = new SmtpClient("smtp.live.com",587); // for hotmail
    objsmtp.EnableSsl = true;
    objsmtp.Credentials = objNC;
    objsmtp.Send(objMail);

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...