asp.net VB.net 发送邮件 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( " 自已的163邮件地址 " " 密码 "
client.DeliveryMethod 
=  System.Net.Mail.SmtpDeliveryMethod.Network 
Dim  message  As   New  System.Net.Mail.MailMessage( " 自已的163邮件地址 " " 收件人邮件地址 "
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  

你可能感兴趣的:(asp.net)