可以把此Function加到小弟之前post的http://www.dotblogs.com.tw/blue7016/archive/2009/06/05/8674.aspx common.vb中
再進行測試。
SendMail Function
"--寄送郵件--"#Region "--寄送郵件--"
Public Shared Sub SendMail() Shared Sub SendMail(ByVal from As String, ByVal subject As String, ByVal receive As String, ByVal body As String)
Try
Dim newMail As New System.Net.Mail.MailMessage
Dim smtpMail As New System.Net.Mail.SmtpClient(" yoursmtp ", 25)
'================內文===================
With newMail
.From = New System.Net.Mail.MailAddress(from, "from") '寄件者
.Body = body '內文
.Subject = subject '主旨
For Each value As String In Split(receive, ",")
.To.Add(New System.Net.Mail.MailAddress(value, "to"))
Next
.Bcc.Add(New System.Net.Mail.MailAddress(" yourEmail ", "bcc"))
.IsBodyHtml = True '是否為HTML格式
.Priority = Net.Mail.MailPriority.Normal '優先權
End With
smtpMail.Send(newMail)
Catch ex As Exception
End Try
End Sub
#End Region 測試SendMail Function
SendMail(
"寄件者mail",
"Title",
"收件者mail",
"內文")
ps:使用者須先設定好自已的 mail server 才能進行測試。