发送电子邮件asp.net C# [英] send email asp.net c#
本文介绍了发送电子邮件asp.net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在C#中使用asp.net项目从我的计算机(本地主机)发送电子邮件?
最后,我要我的项目上传至网络服务器,但我想上传之前对其进行测试。
Is it possible to send email from my computer(localhost) using asp.net project in C#? Finally I am going to upload my project into webserver but I want to test it before uploading.
我已经找到现成来源$ C $ CS,并试图在本地主机上运行他们,但他们都没有成功地工作。
例如,这code:
I've found ready source codes and tried run them in localhost, but neither of them work succesfully. For example this code:
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#发送电子邮件?我应该设置一些服务器配置?
So how to send email using asp.net C#? Should I setup some server configurations?
推荐答案
从Asp.Net发送电子邮件:
Sending Email from 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);
这篇关于发送电子邮件asp.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文