VB.NET使用SMTP发送邮件

前端之家收集整理的这篇文章主要介绍了VB.NET使用SMTP发送邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
’需要邮箱支持SMTP功能
Public Function SendMail( ByVal fstr As String , ByVal tstr As String ) As String
Dim smtp As New System.Net.Mail. SmtpClient ( "smtp.qq.com" ,25)
'发件t邮箱?身份Y验证,参?数y分?别e为a 发件t邮箱?登?录?名?和密码?
smtp.Credentials = New System.Net. NetworkCredential ( "888888888@qq.com" , "88888" )
'创建邮件t
Dim mail As New System.Net.Mail. MailMessage ()
mail.Subject = "邮件t主题a"
'主题a编码?
mail.SubjectEncoding = System.Text. Encoding .GetEncoding( "GB2312" )
'邮件t正y文?件t编码?
mail.BodyEncoding = System.Text. Encoding .GetEncoding( "GB2312" )
'发件t人?邮箱?
mail.From = New System.Net.Mail. MailAddress ( "841526269@qq.com" )
'邮件t优?先级?
mail.Priority = System.Net.Mail. MailPriority .Normal
'HTML格?式?的?邮件t,为afalse则发送纯?文?本?邮箱?
mail.IsBodyHtml = True
mail.Body = "邮件t正y文?内容Y"
'添加收?件t人?,如?果?有D多个?,可以?多次?添加
mail.To.Add( "8889@qq.com" )
'定义?附?件t,参?数y为a附?件t文?件t名?,包含?路径?,推?荐?使1用?绝?对?路径?
'如?果?不?需要a附?件t,下?面?三y行D可以?不?要a
'Dim a As New System.Net.Mail.Attachment("附?件t文?件t")
''附?件t文?件t名?,用?于收?件t人?收?到?附?件t时显?示?的?名?称?
'a.Name = "附?件t文?件t名?"
''加入?附?件t,可以?多次?添加
'mail.Attachments.Add(a)
Try
smtp.Send(mail)
Return "发送成功|"
Catch ex As Exception
Return "发送失败" & ex.Message
Finally
mail.Dispose()
End Try
End Function
原文链接:https://www.f2er.com/vb/259496.html

猜你在找的VB相关文章