建立四個TextBox,分別代表 暱稱, email, 主題, 內容,最後在加上一個Button為送出,如下圖所示:
程式碼如下:
Imports System.Net.Mail
Partial Class contacts
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strName As String = TextBox1.Text
Dim strEmail As String = TextBox2.Text
Dim strSub As String = TextBox3.Text
Dim strBody As String = TextBox4.Text
Dim eMail As New MailMessage()
Dim mSender As New MailAddress(strEmail, strName)'strEmail=email帳號本身, strName=在email帳號上顯示的文字
eMail.From = mSender'寄件者
eMail.To.Add("abc@aaa.com")'收件者
eMail.Subject = strSub'寄送email主旨
eMail.Body = strBody'寄送email內容
eMail.IsBodyHtml = True
Dim smtp As New System.Net.Mail.SmtpClient()
smtp.Host = "127.0.0.1"
smtp.Port = 25
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
smtp.Send(eMail)
End Sub
回目錄
回首頁
support!
回覆刪除謝謝
刪除請問下面的
回覆刪除smtp.Host = "127.0.0.1"
smtp.Port = 25
這是代表哪裡的IP呢?
IP:127.0.0.1是執行程式碼的那台主機
刪除Port:25是SMTP國際標準Prot