using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Collections;
public partial class Email_SendEmail : System.Web.UI.Page
{
SqlHepler db = new SqlHepler();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SendMyMail();
}
}
這個很簡單的啊!
示例代碼:
Public Shared Sub SendEmail()
Dim mm As MailMessage = New MailMessage("omgomg25184@sina.com.cn", "aaa@163.com")
mm.Bcc.Add("bbb@163.com")
mm.Subject = "Send email test"
mm.Body = "Just a Test by the asp.net web application!"
mm.IsBodyHtml = True
mm.Priority = MailPriority.High
Dim sc As SmtpClient = New SmtpClient()
'設置smtp(當然你也可以使用web.config之類的配置文件)
sc.Host = "smtp.sina.com.cn"
sc.Port = 25
sc.Credentials = New NetworkCredential("omgomg25184", "password")
Try
sc.Send(mm)
Catch ex As Exception
If (ex Is New SmtpException()) Then
Throw New Exception("Smtp Send Fail!")
Else
Throw New Exception(ex.ToString())
End If
End Try
End Sub