vb.net发送邮件
来源:互联网 发布:布雷德索数据 编辑:程序博客网 时间:2024/04/30 16:25
转自:http://blog.csdn.net/pashine/article/details/18048487
- ''' <summary>
- ''' 通过SmtpClient类发送电子邮件
- ''' </summary>
- ''' <param name="ReceiveAddressList">收件人地址列表</param>
- ''' <param name="Subject">邮件主题</param>
- ''' <param name="Content">邮件内容</param>
- ''' <param name="AttachFile">附件列表Hastable。KEY=文件名,Value文件路径</param>
- Private Function SendMail(ByVal ReceiveAddressList As List(Of String), ByVal Subject As String, ByVal Content As String, _
- Optional ByVal AttachFile As Hashtable = Nothing) As Boolean
- Dim i As Integer
- 'SMTP客户端
- Dim smtp As New System.Net.Mail.SmtpClient("SMTP.163.COM")
- 'smtp.Host = "smtp.163.com" 'SMTP服务器名称
- '发件人邮箱身份验证凭证。 参数分别为 发件邮箱登录名和密码
- smtp.Credentials = New System.Net.NetworkCredential("邮箱账户", "邮箱密码")
- '创建邮件
- Dim mail As New System.Net.Mail.MailMessage()
- '主题编码
- mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312")
- '正文编码
- mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312")
- '邮件优先级
- mail.Priority = System.Net.Mail.MailPriority.Normal
- '以HTML格式发送邮件,为false则发送纯文本邮箱
- mail.IsBodyHtml = True
- '发件人邮箱
- mail.From = New System.Net.Mail.MailAddress("发件人邮箱")
- '添加收件人,如果有多个,可以多次添加
- If ReceiveAddressList.Count = 0 Then Return False
- For i = 0 To ReceiveAddressList.Count - 1
- mail.To.Add(ReceiveAddressList.Item(i))
- Next
- '邮件主题和内容
- mail.Subject = Subject
- mail.Body = Content
- '定义附件,参数为附件文件名,包含路径,推荐使用绝对路径
- If Not AttachFile Is Nothing AndAlso AttachFile.Count <> 0 Then
- For Each sKey As String In AttachFile.Keys
- Dim objFile As New System.Net.Mail.Attachment(AttachFile.Item(sKey))
- '附件文件名,用于收件人收到附件时显示的名称
- objFile.Name = sKey
- '加入附件,可以多次添加
- mail.Attachments.Add(objFile)
- Next
- End If
- '发送邮件
- Try
- smtp.Send(mail)
- MessageBox.Show("邮件发送成功!")
- Return True
- Catch
- MessageBox.Show("邮件发送失败!")
- Return False
- Finally
- mail.Dispose()
- End Try
- End Function
0 0
- vb.net发送邮件
- VB.NET实现邮件发送
- VB.net 发送邮件 Email
- vb.net实现邮件发送
- VB.NET使用SMTP发送邮件
- vb.net 2005 outlook发送邮件 附件 发送箱
- VB.net学习笔记之发送邮件:System.Net.Mail
- [VB.NET源码]发送邮件的示例代码
- vb.net连接Outlook发送邮件(亲自实践)
- 一段VB.NET代码,生成邮件,发送邮件,支持SMTP验证用户名密码.
- [VB.NET]发送电子邮件
- VB.NET 下使用.NET类库(非WEB中的mail)发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- .net发送接收邮件
- 使用.NET发送邮件
- UEditor使用方法
- ASP.NET的反射
- 如何把一张表里的数据update到另一张表
- 使用NOPI导出Excel并将文件保存到服务器
- 带删除按钮的EditText
- vb.net发送邮件
- 遇到问题---myeclipse编辑jsp页面卡
- wp开发无法加载设计器解决方法
- ASP.NET支持多语言
- 将一个数据库表的数据复制到另一个数据库表
- Lesson 5 Nehe
- SQL Server 批量插入数据的两种方法
- sp_executesql介绍和使用
- 使用反射自动添加sql参数