using System;
using System.Text;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Discuz.Web.tools
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
_smtpClient.Host = "mail.gzmsg.com";//指定SMTP服务器
_smtpClient.Credentials = new System.Net.NetworkCredential("yxx@gzmsg.com", "yangxiuxu");//用户名和密码
MailAddress _from = new MailAddress("yxx@gzmsg.com", "杨秀徐");
MailAddress _to = new MailAddress("471812366@qq.com");
MailMessage _mailMessage = new MailMessage(_from, _to);
_mailMessage.Subject = "主题";//主题
_mailMessage.Body = "内容";//内容
_mailMessage.BodyEncoding = System.Text.Encoding.Default;//正文编码
_mailMessage.IsBodyHtml = true;//设置为HTML格式
_mailMessage.Priority = MailPriority.Normal;//优先级
try
{
_smtpClient.Send(_mailMessage);
Response.Write("<script>alert('发送成功啦')</script>");
}
catch (System.Net.Mail.SmtpException ex)
{
Response.Write("<script>alert('发送失败啦')</script>");
}
}
}
}