Dim objmail As New System.Web.Mail.MailMessage
objmail.From = "寄件者的MAIL"
objmail.To = "收件者的MAIL"
//以下是用下拉式選單做到選擇內文的格式Select Case DDList3.SelectedValue
Case 0 objmail.BodyFormat = MailFormat.Text
Case 1 objmail.BodyFormat = MailFormat.Html
End Select
//以下是用下拉式選單做到選擇內文編碼格式Select Case DDList4.SelectedValue
Case 0 objmail.BodyEncoding = Encoding.UTF8
Case 1 objmail.BodyEncoding = Encoding.UTF7
Case 2 objmail.BodyEncoding = Encoding.ASCII
Case 3 objmail.BodyEncoding = Encoding.Unicode
End Select
objmail.Subject = "郵件的主旨"
objmail.Body = "郵件的內文"
//以下是確認是否有附加檔案If mailfile.PostedFile.ContentLength > 0 Then
Dim attachfile As New MailAttachment(mailfile.PostedFile.FileName())
objmail.Attachments.Add(attachfile)
End If
//下面這三行用來設定SMTP SERVER的認證 帳號密碼用的//經驗:先前在公司電腦不需要加這三行, 只需要設定SMTP SERVER即可,
//應該是公司的電腦已經加入網域, 所以不需要對公司的mail server再認證,
//但是最近我在自己電腦上用mdaemon來架mail server, 先前寫的卻不行,
//但是加上以下三行即可 寄出
//否則會出現錯誤訊息"伺服器拒絕了一個或多個收件者地址。伺服器的回應為:550..."
objmail.Fields.Add("
http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
objmail.Fields.Add("
http://schemas.microsoft.com/cdo/configuration/sendusername", "SMTP SERVER帳號")
objmail.Fields.Add("
http://schemas.microsoft.com/cdo/configuration/sendpassword", "SMTP SERVER密碼")
SmtpMail.SmtpServer = "MAIL SERVER ADDRESS"
SmtpMail.Send(objmail)
標籤: .net, VB