2013年9月25日 星期三

ASP.NET web發送email範例


Imports System.Net.Mail
 Dim client As New System.Net.Mail.SmtpClient()
client.Host = "smtp.163.com"
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential("自已的郵件位址", "密碼")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim message As New System.Net.Mail.MailMessage("自已的郵件地址", "收件人郵件地址")
message.Subject = "主題測試"
message.Body = "asp.net發送郵件"
message.BodyEncoding = System.Text.Encoding.UTF8
message.IsBodyHtml = True
'添加附件需將(附件先上傳到伺服器)
Dim data As New System.Net.Mail.Attachment("Upload\File1.rar", System.Net.Mime.MediaTypeNames.Application.Octet)
message.Attachments.Add(data)
Try
    client.Send(message)
    Response.Write("Email successfully send.")
Catch ex As Exception
    Response.Write("Send Email Failed." + ex.ToString())
End Try

沒有留言:

張貼留言