谁教我用aspx写一个发邮件的代码

来源:百度知道 编辑:UC知道 时间:2024/07/06 14:19:27
有写过这类代码的教教我;
联系方式:
QQ:367088093
Msn:dengzhonghuei@hotmail.com
Skype:hochen_leo
Email:leo@hochen.com.cn
老大我是说C#。Asp.Net

protected void Button1_Click(object sender, EventArgs e)
{
string add = this.TextBox1.Text;//获取收件人地址
string fujian = this.File1.Value;//附件地址
try
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(new MailAddress(add));//收件人
mail.From = new MailAddress("帐号");//发件人(你自己的邮箱,必须是可以用的,因为我是用的新浪的代理,所以你需要一个新浪的邮箱,你也可以用其他的代理)
mail.Subject = "邮件发送";//邮件标题
mail.Body = "邮件发送成功!";//内容
if (fujian.Length > 0)
{
mail.Attachments.Add(new Attachment(fujian));
}
mail.BodyEncoding = System.Text.Encoding.UTF8;//格式

System.Net.Mail.SmtpClient send = new System.Net.Mail.SmtpClient();
send.Host = "smtp.sina.com.cn";//代理服务器
send.Port = 25;//端口
send.Credentials = new System.Net.NetworkCredential("帐号", "密码");//验证发信人(密码)
send.DeliveryMethod = SmtpDeliveryMethod.Network;
send.Send(mail);